Reputation: 177
I have a list of IP's in a csv file and I need to search for any encounters of this IP's in a whole bunch of archived logs but only for file in January.
I first tried this:
for i in `cat /tmp/ips.csv`; do zgrep -rHc $i /webstats/2010/some_dir/*/*.2010-01*.access.gz ; done
But that doesn't work. I get:
bash: /usr/bin/zgrep: Argument list too long
However I thought using find + xargs but I'm not that sure on how I should build my expression. I was thinking of this:
find /logs/2010/some_dir/ -name *.2010-01*.access.gz -type f -print0 | xargs zgrep -rHc `/tmp/ips.csv` {}
But something doesn't look that good.
Upvotes: 1
Views: 398
Reputation: 2396
Try this :
find /logs/2010/some_dir -name '*.2010-01*.access.gz' -type f -print0 | xargs -0 zgrep -Hc -f /tmp/ips.csv
Upvotes: 2