4

The command that I have prints out two of the lines whenever FW_6.0.0 is found, below is the code:

grep -oP 'FW_6.0.0, (.*)$' file

Below is the output, both has the same value of FW_6.0.0

FW_6.0.0, SUCCESS
FW_6.0.0, OK

I would like to match two words, that is FW_6.0.0 and SUCCESS that can be found on the same line so that it prints this out:

FW_6.0.0, SUCCESS and eliminates FW_6.0.0, OK

don_crissti
  • 82,805

4 Answers4

6

try using double quotes "":

grep -oP "FW_6.0.0, SUCCESS" file

OR (Because it is a fixed string, not a pattern):

grep -oF "FW_6.0.0, SUCCESS" file

from grep man page:

-F, --fixed-strings
          Interpret  PATTERN  as  a  list  of  fixed strings, separated by
          newlines, any of which is to be matched.  (-F  is  specified  by
          POSIX.)
-P, --perl-regexp
          Interpret PATTERN as a Perl regular expression.  This is  highly
          experimental and grep -P may warn of unimplemented features.
Nidal
  • 8,956
5

If you want to use awk:

awk '/FW_6\.0\.0/ && /SUCCESS/' file
jasonwryan
  • 73,126
4

Try:

grep -o 'FW_6.0.0.*SUCCESS' file

We don't need -P option here.

cuonglm
  • 153,898
2

Through sed,

$ sed -n '/FW_6\.0\.0.*SUCCESS/p' file
FW_6.0.0, SUCCESS
Avinash Raj
  • 3,703