Get the count of IPs from log file in Linux

Anju
Aug 17, 2021

--

awk '{print $1}' apache.log |sort -n | uniq -c |sort -nr | head
  1. Get the IPs from first field of apache.log
  2. Sort the IPs to process it further
  3. Get the count of each IP
  4. Sort the IPs based on count

Using regular expression:

grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" apache.log |sort -n| uniq -c | sort -nr | head

--

--

Anju
Anju

Written by Anju

A DevOps engineer who loves automating everything (almost), exploring new places, and finding peace in nature. Always looking for the next adventure!

No responses yet