Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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).
`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
Not sure what you are trying to do with `wc`, but maybe you are trying to count the number of times 'debug' occurs? In that case, you can count the output of `grep`:
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.
Last edited by notKlaatu; 06-21-2016 at 02:14 PM.
Reason: added a wc example
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.