1

I have a bunch of logs and I don't want to look in each of it individually but instead I'd like to run cat cluster-2010*.log | grep error but the problem is that even though it's returning me what I want I don't have a clue which .log file is containing the error that the previous command was displaying.

How can I solve this?

1
  • 6
    You remove the unneeded cat ? Sep 6, 2016 at 14:53

3 Answers 3

13

grep will tell you itself if you give it the filenames instead of feeding it their content:

grep error cluster-2010*.log
5

That is a Useless Use of Cat. Simply do:

grep error cluster-2010*.log

You will get output similar to this:

bil@daemon:foo %>grep error cluster-2010*.log 
cluster-20105.log:error
cluster-20107.log:error
5

If you don't want a bunch of outputs, for example if I get auth.log for failure and it spits out a few hundred lines, you can use:

grep -l error cluster-2010*.log

which will print nothing if the result is false (doesn't contain the value) or the filename if it does.

If you want to figure out what line number the word you are looking for is on, you can use:

grep -n error cluster-2010*.log

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .