Pick an IP address out of any file

Here is a small one liner which will pull a list of IP addresses from a file, sort them, select only unique ip’s and then list them from greatest to least.

perl -ne 'while (/([0-9]+\.){3}[0-9]+/g) {print "$&\n"};' /var/log/exim_mainlog |uniq -c |sort -nr |head -100

You can also modify this to include an output file by adding

> file.txt

to the end of the string.


I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.