I know there are "sort" and "uniq" out there, however, today's question is about how to utilise AWK to do that kind of a job. Say if I have a list of anything really (ips, names, or numbers) and I want to sort them;
Here is an example I am taking the IP numbers from a mail log:
awk 'match($0,/\[[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\]/) { if ( NF == 8 && $6 == "connect" ) {print substr($0, RSTART+1,RLENGTH-2)} }' maillog
Is it possible to sort them, ips, "on the go" within the same awk command? I do not require a complete answer to my question but some hints where to start.
Cheers!
Asked by Peter
(309 rep)
Mar 30, 2015, 08:10 AM
Last activity: May 22, 2023, 12:01 PM
Last activity: May 22, 2023, 12:01 PM