Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site uvacs.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!ihnp4!zehntel!hplabs!sdcrdcf!sdcsvax!dcdwest!ittvax!decvax!mcnc!ncsu!uvacs!rwl From: rwl@uvacs.UUCP (Ray Lubinsky) Newsgroups: net.unix,net.unix-wizards Subject: Re: sort problems Message-ID: <1822@uvacs.UUCP> Date: Mon, 28-Jan-85 01:19:28 EST Article-I.D.: uvacs.1822 Posted: Mon Jan 28 01:19:28 1985 Date-Received: Sat, 2-Feb-85 14:28:47 EST References: <2040@pegasus.UUCP> Organization: U.Va. CS in Charlottesville, VA Lines: 36 Xref: watmath net.unix:3512 net.unix-wizards:11842 ------------------------------------------------------------------------------ > 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