sort problems

Ray Lubinsky rwl at uvacs.UUCP
Mon Jan 28 16:19:28 AEST 1985


------------------------------------------------------------------------------

> sort << !
>  Abe
> Aba
> !

   The explanation for the first is simple: sort(1) compares the ASCII values
of the first character of each line.  The first character of the line " Abe" is
the space character (octal 040), whereas the first character of the line "Aba"
is 'A' (octal 101).  The lines are sorted in ascending numerical order, hence
"Aba" comes out second, since 040 < 101.

> 
> sort << !
> Abe
> $Aba
> !
> 

   This is a little more obscure.  If you had just done this from standard
input (just typing "sort", then entering lines until you enter the end-of-file
character) you would have found the "$Aba" line would have come first (octal
045 comes before octal 101).  Unfortunately, the way you did it left each line
open to interpretation by the Bourne shell, which thought that "$Aba" was a
shell variable and replaced the line with its value (nothing).

   If you really need to alphabetically sort lines which may be preceded by
tabs or spaces, use the stream editor (sed(1)) to modify the lines on the
fly (eg):  sed 's/^[ @]*//' | sort  (where '@' should be replaced by your
system's tab character).

------------------------------------------------------------------------------

Ray Lubinsky		     University of Virginia, Dept. of Computer Science
			     uucp: decvax!mcnc!ncsu!uvacs!rwl



More information about the Comp.unix mailing list