sd100
sd100

Reputation: 93

Need to sort IPs in Apache log file

I have the Apache access logs. I want a list of IPs sorted by number of accesses they have made (count) but not the count number. Just the IP addresses sorted by access counts.

I have this command I've found here:

cat access_log | awk '{print $1}' | sort -n | uniq -c | sort -nr | head -200 > output.txt

This gives an output like:

10000 66.249.79.18

10000 is the count number. I need the IP only not the count. What is the modified command then?

Upvotes: 0

Views: 341

Answers (1)

SomeGuyOnAComputer
SomeGuyOnAComputer

Reputation: 6208

Try removing the -c for the uniq command. This will eliminate the first column which is the count.

Full command

cat access_log | awk '{print $1}' | sort -n | uniq | sort -nr | head -200

Upvotes: 1

Related Questions