commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
The vi key sequence "!}" will feed the block of lines from the current position to the next blank line to the command provided: in this case "sort -nut. -k 1,1 -k 2,2 -k 3,3 -k 4,4".
The sort is ascending, numeric (-n), removing duplicates (-u), using "." as key delimiter (-t .").
The "-nut." is a memorable mnemonic :-).
The same command (less the "!}") can, of course, be used from command line to sort a file of IP addresses in a text file.
In the command line version, I found it also useful to remove blank lines and comment lines thusly:
< IPaddresses.txt sed -e "/^#/d" -e "/^$/d" | sort -nut. -k 1,1 -k 2,2 -k 3,3 -k 4,4 # sort IP addresses
There are 2 alternatives - vote for the best!
If you can do better, submit your command here.
You must be signed in to comment.