[nflug] grep, sort, uniq - How To Count?

joshj at linuxmail.org joshj at linuxmail.org
Wed Dec 13 09:49:32 EST 2006


Pipe it to this perl dohicky:


perl -e 'while (<STDIN>) { s/^[\s]*//g; ($cnt,$ip) = split(/\s/); if
($cnt > 10) { print "$cnt\t$ip\n"; } }'


There is probably a more unixy way. But that will work.

-Josh


Thus spake Carver, Blake:

> I'm trying to grep some evil link spammer IPs out of an Apache log, and
> I'd like to reduce the number of false positives by limiting the IPs to
> just a certain number of hits to a file, say 10 hits to a Wordpress
> comment file, so I can do this and see hits to that file, and order them
> by hits
>
> grep wp-comments-post /var/log/httpd/access_log | cut "-d " -f2  | sort
> | uniq -c | sort -nr |
>
> But after that last pipe what I'd like to do is pull out just IPs with
> hits greater than 10. I can do "head -20" but that'll only give me the
> top 20 and that can be any number of hits.
>
> Any ideas? Maybe I need to approach it a different way altogether?
>
> Thanks
> Blake
>
_______________________________________________
nflug mailing list
nflug at nflug.org
http://www.nflug.org/mailman/listinfo/nflug



More information about the nflug mailing list