bash的排序顺序寻常。问题的空间? [英] bash sort unusual order. Problem with spaces?

查看:117
本文介绍了bash的排序顺序寻常。问题的空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的时间去到一个错误,追踪回大量排序...

有人能解释为什么我得到这个无序的结果,当bash的文档告诉我的分隔符是从白色到非空白字符的一个过渡?应该不是第一个字段进行排序?

 >排序的myfile.txt
10_10000000 19
10_10000001 20
10_10000002 19
10_10000003 17
10_10000004 16
10_1000000 44
10_10000005 16
10_10000006 16
10_10000007 17
10_10000008 16

使用+​​0当然-1给我我预期的结果:

 >排序+ 0 -1的myfile.txt
10_1000000 44
10_10000000 19
10_10000001 20
10_10000002 19
10_10000003 17
10_10000004 16
10_10000005 16
10_10000006 16
10_10000007 17
10_10000008 16

一些元信息:

 >类型排序
排序散列(如/ bin /排序)

我使用

 排序(GNU的coreutils)5.97
>区域
LANG =的en_US.UTF-8
LC_CTYPE =的en_US.UTF-8
LC_NUMERIC =的en_US.UTF-8
LC_TIME =的en_US.UTF-8
LC_COLLATE =的en_US.UTF-8
LC_MONETARY =的en_US.UTF-8
LC_MESSAGES =的en_US.UTF-8
LC_PAPER =的en_US.UTF-8
LC_NAME =的en_US.UTF-8
LC_ADDRESS =的en_US.UTF-8
LC_TELEPHONE =的en_US.UTF-8
LC_MEASUREMENT =的en_US.UTF-8
LC_IDENTIFICATION =的en_US.UTF-8
LC_ALL =


解决方案

我觉得你看到基于地区的问题。一些(很多?)语言环境影响的方式排序的工作,在某些字符将被忽略。在这种情况下,它看起来像场之间的空间被当你不指定的字段进行排序忽略。取出空间,你可以看到,看起来像它在错误的地方行是正确的。

如果你用不同的语言环境中运行的排序,你可能会得到不同的结果:

  $ LANG = C类的myfile.txt

我的默认语言环境是en_AU.UTF-8,我看你原来的排序结果。当我设置LANG = C,我看你所期望的结果。

Lots of time gone in to a bug, which tracks back to sort...

Can someone explain why I get this unsorted result, when the bash docs tell me the delimiter is a transition from white to non-white characters? Shouldn't the first field be sorted?

>sort myfile.txt
10_10000000 19
10_10000001 20
10_10000002 19
10_10000003 17
10_10000004 16
10_1000000 44
10_10000005 16
10_10000006 16
10_10000007 17
10_10000008 16

of course using +0 -1 gives me my expected result:

>sort +0 -1 myfile.txt
10_1000000 44
10_10000000 19
10_10000001 20
10_10000002 19
10_10000003 17
10_10000004 16
10_10000005 16
10_10000006 16
10_10000007 17
10_10000008 16

Some metainfo:

>type sort
sort is hashed (/bin/sort)

I am using

sort (GNU coreutils) 5.97


>locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

解决方案

I think you are seeing locale-based issues. Some (many?) locales affect the way sort works, in that certain chars will be ignored. In this case, it looks like the space between the fields are being ignored when you don't specify the fields to sort. Remove the space and you can see that the row that looks like it's in the wrong place is correct.

If you run sort with a different locale you'll probably get a different result:

$ LANG=C sort myfile.txt

My default locale is en_AU.UTF-8 and I see your original sort results. When I set LANG=C, I see the results you are expecting.

这篇关于bash的排序顺序寻常。问题的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆