Quote:
Originally Posted by sd1983benson
I need to do a grep count for two strings in the same line. Only need the count for what I am looking at.
Tried: grep -c "Phrase part one" | "phrase part two" *.log
I can do grep -c "Phrase part one" *.log just fine. But need to limit it down to where it has a specific phrase part two because phrase part one could be tied to multiple "types" of phrase part two.
I do not get an error. It just hangs there and I have to break out.
Thanks.
|
I am not sure why you need to count. Here's how I would do it:
Code:
egrep 'Phrase part one.*phrase part two|phrase part two.*Phrase part one' phrases.txt
Phrase part one blah foo bar phrase part two
echo $?
0
As you can see, if grep (or in this case egrep) catches BOTH the phrases on the same line, no matter what phrase appears first, it returns a 0 (success). If you want to, you can expand your script based on the exit code (0) if you need.
Best regards,
HMW
Edit:
The
phrases.txt file I tried this on looks like this:
Code:
Phrase part one blah foo bar phrase part two
Phrase part one phrase foobar zap bom bang
phrase part two silmarillion part Phrase part three