具有相同文本集的文件的不同终端“排序”结果

时间:2017-10-19 12:59:52

标签: shell sorting unicode terminal

下面显示的文件包含不同顺序的同一组行。实际上,它们都已经通过var parada = []; for(var i = 0; i < <%- coords.length%>; i++){ //First loop to fill the array var arr = [<%- coords[i].lon %>, <%- coords[i].lat %>]; //THIS IS THE ERROR LINE! ... says the console... parada.push(arr); } var overlays = []; for (i = 0; i < parada.lenght; i++) { //Second loop to build the overlays overlays.push(new ol.Overlay({ position: ol.proj.fromLonLat([parada[i][0], parada[i][1]]), //With the data of the array above positioning: 'center-center', element: document.getElementById('parada' + i), stopEvent: false })); } for (i = 0; i<overlays.length; i++){ // Last loop to assign the overlays. map.addOverlay(overlays[i]); } 排序了(你可以尝试自己排序);然而,结果显示第4和第5行彼此切换。怎么会发生这种情况?为什么终端sort <filename>命令按不同顺序排序文件?

档案1

sort

文件2:

w_±_± w_±_± 1
w_˚ w_˚ 1
w_ฌ w_ฌ 1
w_㎡ w_㎡ 1
w_ℓ w_ℓ 1

1 个答案:

答案 0 :(得分:0)

非常有趣!它必须是与区域设置相关的内容。我可以让它在C语言环境中工作:

$ LC_ALL=C sort file1
w_±_± w_±_± 1
w_˚ w_˚ 1
w_ฌ w_ฌ 1
w_ℓ w_ℓ 1
w_㎡ w_㎡ 1

$ LC_ALL=C sort file2
w_±_± w_±_± 1
w_˚ w_˚ 1
w_ฌ w_ฌ 1
w_ℓ w_ℓ 1
w_㎡ w_㎡ 1

首先,我可能这可能是由于字符代码的长度,因此字符可能由两个字节组成,其中第一个字节是相同的。让我们调查一下:

$ printf 'w_ℓ w_ℓ 1' |hd; printf 'w_㎡ w_㎡ 1' |hd
00000000  77 5f e2 84 93 20 77 5f  e2 84 93 20 31           |w_... w_... 1|
0000000d
00000000  77 5f e3 8e a1 20 77 5f  e3 8e a1 20 31           |w_... w_... 1|
0000000d

e2 84e3 8e,因此不会发生此类事件。

这可能是因为您的语言环境表明由于某种原因跳过这些字符。对于en_US.UTF-8,GNU coreutils 8.28中的sort至少是这样。