User's manual. Section 1.

SRT(1): sort lines


USAGE

        usage: srt [-1Ddux] [-F sep] {-r key} {file}
            -1: fields separated by 1 run of the field delimiter string
            -D: debug
            -F sep: input field delimiter character(s) (or string under -1)
            -d: do not print dup lines
            -r key: use this field range as the sort key(s)
            -u: use unix out
            -x: sort each extracted text on its own (eg. out from gr -x)
        

DESCRIPTION

Srt sorts files using as keys the ones indicated to the -r flag, in the order in which they were specified. This can be used to sort each input file on its own and to sort output from gx or related commands.

A key is indicated by giving, in this order:

  • A field range
  • A format
  • An optional reverse indicator

A range may be a single line number, counting from 1, or a pair of start and end field numbers separated by a "," character. Negative field numbers count backwards from the end of the line (the last is -1 and so on). A missing start number in a range means 1, and a missing end number in a range means -1. If no range is given, "," is implied. And, when such range is indicated, all fields are printed, one line at a time.

The format may be one of:

  • n to consider that the field is a number.
  • t to consider that the field is a time.
  • s to consider that the field is a string, this is the default when no format is given.

The reverse indicator is "r", causing a sort in reverse order.

By default the field separator is a run of blanks. Flag -F changes the set of runes used as field separators to its argument.

Flag -1 indicates that fields are separated exactly by one instance of the separator string. Such string defaults to a tabulator character in this case, unless -F says otherwise.

EXAMPLES

Sort in ascending string order:

        srt file
        

Sort in reverse numeric order (all fields):

        srt -r nr file
        

Sort all files in the current directory and write them back sorted:

        ; lf -g ,1 | srt -x | wf
        

Sort the second and third fields in ascending numeric order and the last field in reverse string order, for a file separated with a ":" character, honoring empty fields:

        ; srt -1F: -r 2,3n -r -1r file
        

SOURCE

  • /zx/sys/src/clive/cmd/srt


User's manual. Section 1.