unix sort

Problem

You want to perform a sort:

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



Solution

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

See the example tag.



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



Reference

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



Leave a Reply

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