如何使外壳程序的“ uniq”命令对重音不敏感?
# more test
a
à
b
# LC_ALL=fr_FR.UTF-8 uniq test
a
à
b
预期:
# LC_ALL=fr_FR.UTF-8 uniq test
a
b
注意:以下操作不正确,因为它会更改输入数据:
cat test | sed "s/à/a/" | uniq
这适用于您的简单示例:
$ cat letters.txt
a
à
b
$ paste <(iconv -f utf8 -t ascii//translit letters.txt) letters.txt | sort -s -k1,1 -u | cut -f2
a
b
[它需要iconv
的GNU版本支持对输出编码的音译,以及像bash
或zsh
这样的支持<(command)
重定向的外壳。