How to sort on exactly one field only

Stephen Quan quan at sol.surv.utas.oz
Wed Oct 24 12:34:16 AEST 1990


ARaman at massey.ac.nz (Anand Venkata Raman) writes:

>I want to sort a file exclusively on field #2.
>For example,
>A portion of the file looks like
>appl1  3  Submitted
>appl2  4  Submitted
>appl1  3  Started
>appl3  5  Submitted
>appl2  4  Started
>appl1  3  Finished(0)
>appl2  4  Finished(7)
>appl3  5  Started
>appl3  5  Finished(3)

In the bourne shell (sh) :

cat -n file | awk "{print \$3,\$1,\$2,\$4}" | sort | awk "{print \$3,\$1,\$4}"
- line numbers are added
- arguments are rearrange so :
- sort is done on first preference your key, second preference line numbers
- remove the line# are rearrange arguments back

I think I am missing some argument to 'sort' to make it interpret the line
numbers as numbers - not just text.

Stephen Quan,
University of Tasmania.



More information about the Comp.unix.questions mailing list