BASH – How to count the number of IP addresses in a log file


Sometimes it’s useful to see how many times a specific IP address appears in a log file. In this article we explore one method using grep and uniq.

grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" /path/to/sourcefile | sort > output.txt


uniq -c output.txt | awk '{print $2": "$1}'


Share this article

Leave a Reply

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

Scroll to Top