NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Question of sort(1)



    Date:        Sat, 28 May 2016 21:02:58 +0800 (PHT)
    From:        Paul Goyette <paul%whooppee.com@localhost>
    Message-ID:  <Pine.NEB.4.64.1605282053260.5162%pokey.whooppee.com@localhost>

  | and execute 'sort -t / -k 1 < IN' (field separator is /, sort on first 
  | field) I get (what I believe to be) incorrect results:

No, what you get is correct.

  |  	# sort -k1 -t / < IN

-k1 means from the start of field 1 to end of line.   From the man page:

     Fields are specified by the -k field1[,field2] argument.  A missing
     field2 argument defaults to the end of a line.

Posix says the same, in slightly different words...

	-k field_start[type][,field_end[type]]

	shall define a key [...]
	A missing field_end shall mean the last character of the line.

'-' < '/' hence a-0/y < a/z

  | Interestingly, it works as expected if the field delimiter is set to a 
  | space (and the input data updated accordingly):

That's because ' ' < '-'.

  | So, is this a bug?  Or is this working-as-designed (and therefore my 
  | expectations need to be reset)?

The latter.   For what you want, use -k1,1

	sort -t/ -k1,1 /tmp/F
	a/z
	a-0/y
	a-1/x

kre



Home | Main Index | Thread Index | Old Index