相关疑难解决方法(0)

locales如何在Linux/POSIX中工作以及应用了哪些转换?

我正在处理(希望)UTF-8文本的大文件.我可以使用Ubuntu 13.10(3.11.0-14-generic)和12.04重现它.

在调查一个bug我遇到了奇怪的行为

$ export LC_ALL=en_US.UTF-8   
$ sort part-r-00000 | uniq -d 
? ? ? ? 251
? ? ? ? ?       291
? ? ? ? 301
? ?     475
? ?     565

$ export LC_ALL=C
$ sort part-r-00000 | uniq -d 
$ # no duplicates found
Run Code Online (Sandbox Code Playgroud)

运行使用读取文件的自定义C++程序时也会出现重复项std::stringstream- 由于使用en_US.UTF-8区域设置时出现重复,它会失败. C++似乎至少对于std::string输入/输出没有影响.

为什么在使用UTF-8语言环境时找到重复项,并且在C语言环境中找不到重复项?

导致此行为的文本的区域设置有哪些转换?

编辑:是一个小例子

$ uniq -D duplicates.small.nfc 
? ? ? ? ?       224
? ? ? ? ?       224
? ? …
Run Code Online (Sandbox Code Playgroud)

linux locale posix utf-8 gnu-coreutils

11
推荐指数
1
解决办法
5525
查看次数

linux实用程序如何"排序"工作?(为什么它不像我认为的那样工作?)

我有2个文本文件:

$ cat /tmp/test1
"AAP" bar
"AEM" bar
"AA" bar
"AEO" bar
"A" bar

$ cat /tmp/test2
"AEM" foo
"AAP" foo
"A" foo
"AEO" foo
"AA" foo
Run Code Online (Sandbox Code Playgroud)

我想对它们进行排序

$ sort /tmp/test1
"AA" bar
"AAP" bar
"A" bar              <-- "A" is in position 3
"AEM" bar
"AEO" bar

$ sort /tmp/test2
"AA" foo
"AAP" foo
"AEM" foo
"AEO" foo
"A" foo              <-- "A" is in position 5
Run Code Online (Sandbox Code Playgroud)

为什么"A"最终位于第3位/tmp/test1第5位/tmp/test2

我的期望是每列的每个字符都要进行比较.

因此,当比较第3列时'A' …

linux sorting

3
推荐指数
1
解决办法
424
查看次数

标签 统计

linux ×2

gnu-coreutils ×1

locale ×1

posix ×1

sorting ×1

utf-8 ×1