uniq,如何不区分重音?

问题描述 投票:0回答:1

如何使外壳程序的“ 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
shell uniq
1个回答
0
投票

这适用于您的简单示例:

$ 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版本支持对输出编码的音译,以及像bashzsh这样的支持<(command)重定向的外壳。

© www.soinside.com 2019 - 2024. All rights reserved.