unix sort

[problem]

You want to perform a sort:

… But ignore leading blanks;
… Perform numerical sort;
… Offset it to the third column;
… Reverse it;

[/problem]

[solution]

As always with UNIX we supply the arguments, with letters.

See the example tag.

[/solution]

[example]

8 flags to the UNIX sort command.

1) -b # ignores leading blanks.

2) -f # ignore case

3) -n # numerical

4) -r # reverse

5) –key=pos# # sort by key or +# in Solaris, etc take note of -t though for field separator

6) -o # output to file, useful for doing a sort -o fileA fileA – rather than redirect than can overwrite.

7) -u # strip unique lines. You can also use the uniq command, which includes a -c option to count repeating lines.

8) -i # ignore non-printable chars

[/example]

[reference]

[tags]UNIX Sort, UNIX, sort, UNIX Coding School[/tags]

[/reference]

If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

Your email address will not be published. Required fields are marked *