Thoughts that are my own.

Simple Sorts

Since I am apparently unable to remember how to do a simple sort, I’m going to throw it into my blog so I can refer to it later.

In this particular case, I was attempting to pull out all of the “from=” entries in the server’s mail logs. I won’t go into the details of the awk command, but I will paste my entire command here anyway, including the sorts:

cat maillog | grep from= | awk '{ print $6 }' | sort | uniq -c | sort -n

The summary of the above command is this:

I cat the mail log on the server and using awk I pull out the 6th column (columns separated by spaces) and then I apply the sort. The first sort does a general sort on that column. The ‘uniq -c’ does a count of the number of times a unique entry appears from the first sort. The final ‘sort -n’ sorts the output of the uniq command in numerical order so it is easier to read.