Unix shell prgrams and AI techniques

Greg Limes limes at sun.uucp
Thu Jun 23 01:59:05 AEST 1988


In article <133 at quintus.UUCP> ok at quintus.UUCP (Richard A. O'Keefe) writes:
>In article <514 at philmds.UUCP> leo at philmds.UUCP (L.J.M. de Wit) writes:
>:B.T.W. Testing this script I discovered what seems to be a bug in sort
>:(Ultrix 2.0).
>:The following two lines when fed into sort -u +15:
>:                Mon Jun 20 19:36   still logged inuucp      ttyic
>:                Mon Jun 20 18:07   still logged inleo       ttyid
>:generate only one line:
>:                Mon Jun 20 19:36   still logged inuucp      ttyic
>:The manual says: A missing -num argument means the end of the line,
>:and for u: Suppress all but one in each set of equal lines. Ignored bytes
>:and bytes outside keys do not participate in the comparision. 
>:Am I wrong or is the manual wrong (or is sort buggy)?
>
>Trying "sort -u +15" with just these two records on a Sun-3/50 running
>SunOS 3.2, I get as output whichever of the two records came first.
>There are said to be problems with the -u option of sort, so I always
>avoid it.  "sort +15 | uniq" works fine.

(Good thing my flame thrower is in the shop)]

It works even better if you use +.15; that little dot between the plus
sign and the one is kind of important. 

The general form is +f.c, where f is the number of fields to skip and c
is the number of characters to skip. Beats me why you would want to
skip either fifteen characters or fifteen fields above; if you wanted to
start your sort at "still", I would use +4 instead. And yes, the -u
option does precisely what the manual claims. In the above example, of
course, all the keys were empty and therefore equal. Using "-u +4" would
sort the records, leaving one line per login name per tty.

-- Redhead [limes at sun.com]			R.T.F.M.



More information about the Comp.unix.questions mailing list