Linux script for searching logs

southpau1
southpau1 used Ask the Experts™
on
I have 31 log files in a directory.  I want to search each log file for a specific string.  It would be nice to search all 30 with a single command.  For output I would just like a count of the matches.  How can I accomplish this?

Directory name: /logs
Log file naming convention:
system.log  -  (today's log)
system.log.* -  (previous 30 day's logs where * is the number 1-30)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2013
Top Expert 2013
Commented:
cd /logs
grep -c "specific string" system.log*

gives a count of matches per file.
Try
grep "STRING" system.log*

Open in new window


Use -c option to count matches
Most Valuable Expert 2013
Top Expert 2013
Commented:
To get only a total count of matches (a single number):

grep -hc "specific string" system.log* | awk '{s+=$1} END {print s}'

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial