MESSAGE
DATE | 2013-06-10 |
FROM | Ruben Safir
|
SUBJECT | Subject: [NYLXS - HANGOUT] [ruben@mrbrklyn.com: Re: sort bug?]
|
----- Forwarded message from Ruben Safir -----
Date: Mon, 10 Jun 2013 02:43:30 -0400 From: Ruben Safir To: mrbrklyn-at-panix.com Subject: Re: sort bug? User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5
[This mail was also posted to comp.os.linux.misc.]
On Sat, 08 Jun 2013 22:42:43 +0000, John McCue wrote:
> ruben safir wrote: >> Is there a bug in sort? >> >> >> unexpected output: >> >> ls -alh|sort -k5 -h -r|less >> > > > What Linux distro ? Seems on RedHat/Fedora type distros I need to set: > LC_ALL=POSIX > to allow sort to work the way I believe it should. > > HTH John
opensuse 12.1
It seems to not like leading white space, which is confusing since that space is the seperator. This behavior would not be aligned with what happens with awk.
Anway, the key might lie in this difficult to understand sentence in the man page:
KEYDEF is F[.C][OPTS][,F[.C][OPTS]] for start and stop position, where F is a field number and C a character position in the field; both are origin 1, and the stop position defaults to the line's end. ***If neither -t nor -b is in effect, characters in a field are counted from the beginning of the preceding whitespace.***
I think -h dislikes the leading white space?
for example:
ls -alh|sort -k5bh ..... -rw-r--r-- 1 ruben users 40M Feb 6 2012 rav.ogg -rw-r--r-- 1 ruben users 47M May 22 07:27 MVI_2522.MOV -rw-r--r-- 1 ruben users 59M May 3 03:09 IMG_2058.png -rw-r--r-- 1 ruben users 88M Sep 16 2011 mov07031.mpg -rw-r--r-- 1 ruben users 173M May 16 2011 Star_Trek_TNG_-_4x15_- _First_Contact.avi -rw-r--r-- 1 ruben users 330M Jan 4 2010 grandmashouse.mpg -rw-r--r-- 1 ruben users 692M Jun 7 2011 Green Lantern Emerald Knights.mkv -rw-r--r-- 1 ruben users 701M Aug 28 2011 natural.avi -rw-r--r-- 1 ruben users 954M May 22 07:27 MVI_2430.MOV -rw-r--r-- 1 ruben users 1.7G Mar 4 01:51 network-001.ogm
That looks about right.
ALSO
LS_ALL set to POSIX does seem to fix the problem. These environments have gotten very hairy over the years. A quick grep of LC_ALL from the output of set in bash reveals
ruben-at-workstation:~> set|grep LC_ALL LC_ALL=POSIX for foo in $(LC_ALL=C $SCOUT 2>&1 | sed -e "1,/Available modules:/ d" | egrep [a-z] | awk -F ' ' '{print $1}'); YAST_MODLIST=($(LC_ALL=C $YAST -l| grep '^[a-z]' | grep -v "Available")); MODOPTS=(`LC_ALL=C $YAST $mod $prev help 2>&1 | while read line ; do MODOPTS=(` LC_ALL=C $YAST $mod help 2>&1 | while read line ; do ZYPPER_CMDLIST=($(LC_ALL=POSIX $ZYPPER -q -h | sed -rn '/^[[:blank:]]*Commands:/,$ { opts=(${opts[-at-]}$(echo; LC_ALL=POSIX $ZYPPER -q lr | sed -rn '/^[0-9]/{ opts=(${ZYPPER_CMDLIST[*]}$(echo; LC_ALL=POSIX $ZYPPER -q help 2>&1 | sed -rn '/Global Options:/,/Commands:/{ opts=$(LC_ALL=POSIX $ZYPPER -q help $command 2>&1 | sed -e "1,/ $magic_string/d" -e 's/.*--/--/' -e 's/ .*//'); opts=(${opts[-at-]}$(echo; LC_ALL=POSIX $ZYPPER -q lr | sed -rn '/^[0-9]/{ opts=(${opts[-at-]}$(echo; LC_ALL=POSIX $ZYPPER -q ls | sed -rn '/^[0-9]/{ opts=(${opts[-at-]}$(echo; LC_ALL=POSIX $ZYPPER -q ll | sed -rn '/^[0-9]/{
What is LC_ALL?
Ruben
Oh man... KISS KISS KISS
-- The Coin Hangout: http://www.coinhangout.com/home
----- End forwarded message -----
|
|