Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash tr正在破坏utf-8编码_Bash_Character_Tr - Fatal编程技术网

Bash tr正在破坏utf-8编码

Bash tr正在破坏utf-8编码,bash,character,tr,Bash,Character,Tr,我有以下意见: 我想知道;2004年2月14日San_Sebastián Gerona出口的旅游价格?如果可能的话,在城际旅行 圣塞巴斯蒂安 我期待同样的结果,但是没有“,/*?”,所以我决定做一个tr-d。我的灵魂在于当我这样做的时候: cat log | tr -d ".,/*¡?;¿!" >> output.log 我看到: i would like to know the price of travel San_Sebasti<C3>n Gerona exit

我有以下意见:

我想知道;2004年2月14日San_Sebastián Gerona出口的旅游价格?如果可能的话,在城际旅行

圣塞巴斯蒂安

我期待同样的结果,但是没有“,/*?”,所以我决定做一个tr-d。我的灵魂在于当我这样做的时候:

cat log | tr -d ".,/*¡?;¿!" >> output.log
我看到:

 i would like to know the price of travel San_Sebasti<C3>n Gerona exit
 the fourteenth of february two thousand four and if possible travel in
 intercity
我想知道San_Sebastin Gerona出口的旅游价格
2004年2月14日,如果可能的话,在
城际
sanu Sebastin

它打破了文本中的所有重音,但不知道为什么要用Perl来拯救

perl -CSAD -pe 'tr=.,/*?;!¿¡==d' < log >> output.log
perl-CSAD-pe'tr=,/*?;!?==d'>output.log
Perl的
tr//
tr
的工作原理类似,我使用
=
而不是
/
来避免反斜杠


-C
为stdin、stdout和stderr、参数(A)和输入+输出流(D)打开utf-8。在这种特殊情况下只需要S。

命令tr中断重音字符,因为它不理解多字节字符(所有重音字符在utf-8中都是多字节字符)

您可以使用sed(它可以很好地解释多字节字符):


方括号缺失。另外,它只在
*.UTF-8
locale下工作。我最后放了这个:
sed“s/[,/*?;]///g”
请参见:
cat log | sed 's#[.,/*¡?;¿!]##g' >> output.log