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

Background

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

then

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

References

Share this article

Leave a Reply

Your email address will not be published.

Scroll to Top