Sed 大写具有国际字母的名称,如éèàö;

Sed 大写具有国际字母的名称,如éèàö;,sed,locale,capitalize,csv,Sed,Locale,Capitalize,Csv,我在RHEL 6.3上的尝试: $ export LC_ALL=fr_FR.utf-8 $ sed 's/ \([a-zA-Zé]\)\([^ ]*\) /[\u\1\L\2\E] /g' <<< " hélène NOËL étienne " hélène NOËL étienne $ export LC_ALL=C $ sed 's/ \([a-zA-Zé]\)\([^ ]*\) /[\u\1\L\2\E] /g' <<< " hélène

我在RHEL 6.3上的尝试:

$ export LC_ALL=fr_FR.utf-8
$ sed 's/ \([a-zA-Zé]\)\([^ ]*\) /[\u\1\L\2\E] /g' <<< " hélène  NOËL  étienne "
 hélène  NOËL  étienne

$ export LC_ALL=C
$ sed 's/ \([a-zA-Zé]\)\([^ ]*\) /[\u\1\L\2\E] /g' <<< " hélène  NOËL  étienne "
[Hÿlÿne] [Noÿl] [ÿtienne]

$ sed --version
GNU sed version 4.2.1
[...]
这对你合适吗

kent$  echo " hélène  NOËL  étienne "|sed -r 's/(\S)(\S+)/[\U\1\L\2]/g'
 [Hélène]  [Noël]  [Étienne] 
我的sed版本与你的有点不同,但我认为应该在那里运行:

kent$  sed --version |head -1
sed (GNU sed) 4.2.2
添加了我的区域设置,您可能想知道:

kent$  echo $LANG
en_US.utf8

kent$  locale
LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=
没有解决我的问题,但我没有向他提供我所有的约束条件。我的输入文件如下所示:

sfou;STéphane Foù - stephane.fou@example.com;;
fbar;frédéric bâr - frederic.bar@example.com;;
hnoel;Hélène NOËL - helene.noel@example.com;;
脚本应仅大写名称:

sfou;Stéphane Foù - stephane.fou@example.com;;
8945;Frédéric Bâr - frederic.bar@example.com;;
hnoel;Hélène Noêl - helene.noel@example.com;;

基于,我成功地通过了以下脚本:

LC_ALL=fr_FR sed -r 's/(\w)(\w*) /\U\1\L\2 /g' test.cvs

其他地区没有给出正确的结果:

$ LANG=fr_FR.utf8 LC_ALL= sed -r 's/(\w)(\w*) /[\U\1\L\2] /g' test.cvs
sfou;STé[Phane] Foù - stephane.fou@example.com;;
fbar;frédé[Ric] bâ[R] - frederic.bar@example.com;;
hnoel;Hélè[Ne] NOË[L] - helene.noel@example.com;;

$ LANG=C LC_ALL= sed -r 's/(\w)(\w*) /[\U\1\L\2] /g' test.cvs
sfou;STé[Phane] Foù - stephane.fou@example.com;;
fbar;frédé[Ric] bâ[R] - frederic.bar@example.com;;
hnoel;Hélè[Ne] NOË[L] - helene.noel@example.com;;

$ LANG=en_US.utf8 LC_ALL= sed -r 's/(\w)(\w*) /[\U\1\L\2] /g' test.cvs
sfou;STé[Phane] Foù - stephane.fou@example.com;;
fbar;frédé[Ric] bâ[R] - frederic.bar@example.com;;
hnoel;Hélè[Ne] NOË[L] - helene.noel@example.com;;
地区
en_-US
fr_-fr
(无
.utf8
)正常:


注意:我从中发现了
\w

谢谢Kent。请您添加关于
-r
\S
含义的解释(您可以提供一些链接)。你知道地区
en_US
en_US.utf8
之间的区别吗?你知道为什么脚本在使用
en_US.utf8
locale时无法工作吗?干杯
$ LANG=fr_FR.utf8 LC_ALL= sed -r 's/(\w)(\w*) /[\U\1\L\2] /g' test.cvs
sfou;STé[Phane] Foù - stephane.fou@example.com;;
fbar;frédé[Ric] bâ[R] - frederic.bar@example.com;;
hnoel;Hélè[Ne] NOË[L] - helene.noel@example.com;;

$ LANG=C LC_ALL= sed -r 's/(\w)(\w*) /[\U\1\L\2] /g' test.cvs
sfou;STé[Phane] Foù - stephane.fou@example.com;;
fbar;frédé[Ric] bâ[R] - frederic.bar@example.com;;
hnoel;Hélè[Ne] NOË[L] - helene.noel@example.com;;

$ LANG=en_US.utf8 LC_ALL= sed -r 's/(\w)(\w*) /[\U\1\L\2] /g' test.cvs
sfou;STé[Phane] Foù - stephane.fou@example.com;;
fbar;frédé[Ric] bâ[R] - frederic.bar@example.com;;
hnoel;Hélè[Ne] NOË[L] - helene.noel@example.com;;
$ LANG=en_US LC_ALL= sed -r 's/(\w)(\w*) /[\U\1\L\2] /g' test.cvs
sfou;[Stéphane] [Foù] - stephane.fou@example.com;;
fbar;[Frédéric] [Bâr] - frederic.bar@example.com;;
hnoel;[Hélène] [Noël] - helene.noel@example.com;;

$ LANG=fr_FR LC_ALL= sed -r 's/(\w)(\w*) /[\U\1\L\2] /g' test.cvs
sfou;[Stéphane] [Foù] - stephane.fou@example.com;;
fbar;[Frédéric] [Bâr] - frederic.bar@example.com;;
hnoel;[Hélène] [Noël] - helene.noel@example.com;;