find/grep question
I'm using the following command to get the number of *.log files containing "yes" or "no" at the end of the file (the files are large and I'm looking for "yes" or "no" near the end of each file, and each file will contain at most one "yes" OR one "no", but never both):
find ./OUTPUT -type f | grep '\.log' | xargs -l tail -20 {} | grep 'yes\|no' | wc -l This works fine. Now I need the filenames that DO NOT contain "yes" or "no". How do I modify the above command to do that? Thanks! |
looks like a homework
at first I would suggest you to check the man page of grep about possible options. |
grep -v does inverse matching (see man grep)
Oops, sorry pan64, I posted this at the same time as you. I wasn't wanting to overrule your advice. @ocrts: Welcome to LQ. :) Is this a homework question or something you're trying to achieve in the real world? Just interested. |
Not a homework. Professional. I'm a little old for homework ;). Just made the text generic. I have checked the man pages. The -v option will just list all the lines that don't contain "yes" or "no". I need the filenames. I tried the -l option on the second grep and send the output to a file (instead of wc -l) to get the filenames of those that do contain "yes" or "no", but I get a broken pipe on the xargs.
|
How 'near' is "near the end of a file"?
|
"near" is within the last 20 lines. Since the log files are >10MB each and there are ~10k files, the -tail significantly reduces the execution time of the command as it isn't searching the entirety of each file.
|
Quote:
Something like Code:
#!/bin/bash |
Quote:
Code:
find ./OUTPUT -type f -name '*.log' | xargs -l tail -20 {} | grep -c 'yes\|no' I would use a more powerful language, but you can also list the files containing yes and no and removes them from the full list (which is actually only one additional grep and a small script) |
And you can replace xargs -l with find -exec
Code:
find ./OUTPUT -type f -name '*.log' -exec tail -20 {} \; | grep -c -e 'yes' -e 'no' |
All times are GMT -5. The time now is 05:26 AM. |