searching in log files
Hello,
First of all, as I am new to Linux, I would like to thank all of you who helped me with my last question. Today I am playing around with regular expressions and log files. What I'd like to be able to do is search a log file and display the number of lines that contain DEBUG issues (for example)? I have tried using cat [filename] | wc -l grep -i debug this gives me errors and says -i is not used with wc (I thought I was using it with grep). Thanks for any assistance you can give. |
`wc` is a word counting command (words, lines, characters). Why are you using it here at all? Are you trying to also get the total number of words in a log file?
Also, you don't need to `cat` a file to `grep` it. That's like opening a JPG in GIMP, and then going to File > Open and opening that same file in GIMP again. It's already open, you don't have to open it again. Try something like: Code:
grep -i debug /path/to/log/file Code:
grep -i debug /path/to/log/file | wc -l Try running those command separately; first do just the grep, and then the grep and wc. It will make more sense that way: the first just greps the file for the 'debug' string, while the second detects each grep "hit" and adds it to the count, providing you with the summary at the end. |
Just as you have piped the output of "cat" (unnecessary in this case as implied above) to "wc-l", you would need to pipe the output of "wc -l" to grep. It will not do as you apparently expect. But try it anyway and see if you an figure out why.
grep has a "-c" parameter you might find of interest. |
Try this:
Quote:
man grep --> https://www.gnu.org/software/grep/manual/grep.html Check out this link also: http://quickbytesstuff.blogspot.sg/2...currences.html |
$ grep -c debug /var/log/messages
will give the number of lines that contain "debug". |
Thanks.
I was indeed trying to utilize the wc to figure out the number of line in the file that contain the word debug. I'm new to linux so I was using the cat to get into the file to read it. As a follow on question, I noticed a large number of debug issues and now I would like to narrow the search. Perhaps is there a way to use a logical AND to find the number lines to contain both debug AND "symbolic link" (say i want to isolate the number of debug issues that are related to symbolic links. How about a logical OR? say i want to find the number of lines that contain either the word bytes OR links. |
Thanks.
I was indeed trying to utilize the wc to figure out the number of line in the file that contain the word debug. I'm new to linux so I was using the cat to get into the file to read it. As a follow on question, I noticed a large number of debug issues and now I would like to narrow the search. Perhaps is there a way to use a logical AND to find the number lines to contain both debug AND "symbolic link" (say i want to isolate the number of debug issues that are related to symbolic links. How about a logical OR? say i want to find the number of lines that contain either the word bytes OR links. |
Actually OR is simpler:
Code:
# lines that contain word1 OR word2 (maybe both, or just one or another) Code:
# lines that contain word1 AND word2 (require both) |
I use piped grep because it's easy to remember:
$ grep -i debug | grep snd-hd will output every line with both "debug", either upper or lower case, and "snd-hd". I believe the "|" within the regular expression means, "or". |
All times are GMT -5. The time now is 06:18 AM. |