gpt4 book ai didi

linux - gnu sort 在 MacOS Linux 上产生不同的结果

转载 作者:行者123 更新时间:2023-12-03 09:51:41 25 4
gpt4 key购买 nike

我试图在 MacOS Mavericks 和 Linux Centos 6.5 上获得相同的 GNU 排序输出。我已经在 MacOS 上安装了最新的“brew”gsort。对完全相同的文件进行排序时,我从两个平台上的排序得到不同的输出结果:特别是“#”字符的处理方式。以下是排序后的文件的第一行,您可以在其中非常清楚地看到差异:

MacOS brew gsort:

SENT_ID1###de peu ||| and gustav stresemann ||| 1.0<br/>
SENT_ID1###en compagnie d' aristide briand ||| only just missed achieving ||| 1.0<br/>
SENT_ID1###et de gustav stresemann ||| their aim ||| 1.0<br/>
SENT_ID1###il a manqué cet objectif ||| he and aristide briand ||| 1.0<br/>
SENT_ID10###dans le même esprit ||| still ||| 1.0<br/>
SENT_ID10###de comblement ||| with the same aim of making good ||| 1.0<br/>
SENT_ID10###de nos institutions européennes ||| of institutional democracy ||| 1.0<br/>

等等

在 CentOS 上使用“排序”的相同文件:

SENT_ID10000###car il constitue l' ||| as it constitutes ||| 1.0<br/>
SENT_ID10000###de ce débat ||| of this debate ||| 1.0<br/>
SENT_ID10000###nous pensons ||| we think ||| 1.0<br/>
SENT_ID10000###que ce paragraphe aurait mérité ||| that this section would have merited ||| 1.0<br/>
SENT_ID10000###un des défis majeurs ||| one of the major challenges ||| 1.0<br/>

SENT_ID10000###un plus ample développement ||| further development ||| 1.0<br/>
SENT_ID10001###à aucune règle si ce n' est celle du marché ||| only to market rules ||| 1.0<br/>
SENT_ID10001###ces systèmes complémentaires ||| these supplementary systems ||| 1.0<br/>
SENT_ID10001###en augmentation ||| which are increasing ||| 1.0<br/>
SENT_ID10001###ne sont soumis ||| are subject ||| 1.0<br/>

等等

在 CentOS 下,零字符优先于 'hash' 字符,正如您所看到的,排序顺序完全不同。 gsort MacOS 排序顺序是我所期望的。谁能告诉我为什么 CentOS 排序顺序是错误的,我该如何纠正?

最佳答案

我在 macOS 和 Linux 上看到了不同的行为,即使两个系统上的 locale 显然相同。

如果您使用 LC_COLLATE=CLC_COLLATE=POSIX,它至少应该在两个操作系统之间保持一致。

ma​​cOS,fr_FR.UTF-8:

$ (export LC_COLLATE=fr_FR.UTF-8; echo -e 'a\nA\na.1\nA.1\na1\nA1\na#1\nA#1' | gsort)
A
A#1
A.1
A1
a
a#1
a.1
a1

请注意,大写字母排在小写字母之前,# 排在 .. 之前,排在 1 之前。

Linux (RH6), fr_FR.utf8:

$ (export LC_COLLATE=fr_FR.utf8; echo -e 'a\nA\na.1\nA.1\na1\nA1\na#1\nA#1' | sort)
a
A
a1
a.1
a#1
A1
A.1
A#1

请注意大写字母排在小写字母之后,1 排在 .. 之前 # 之前。

现在使用 POSIX:

苹果操作系统:

$ (export LC_COLLATE=POSIX; echo -e 'a\nA\na.1\nA.1\na1\nA1\na#1\nA#1' | gsort)
A
A#1
A.1
A1
a
a#1
a.1
a1

Linux:

$ (export LC_COLLATE=POSIX; echo -e 'a\nA\na.1\nA.1\na1\nA1\na#1\nA#1' | sort)
A
A#1
A.1
A1
a
a#1
a.1
a1

有趣的是,macOS 默认排序规则似乎更接近 POSIX 标准。我想知道这背后的历史。

关于linux - gnu sort 在 MacOS Linux 上产生不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22198288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com