Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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, 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

share|improve this question
Is the order matter? – cuonglm Jul 4 '14 at 3:27
Yes FW_6.0.0 should come first. – user3081935 Jul 4 '14 at 3:28
up vote 6 down vote accepted

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
-P, --perl-regexp
          Interpret PATTERN as a Perl regular expression.  This is  highly
          experimental and grep -P may warn of unimplemented features.
share|improve this answer
thanks so much for the help, it works great! – user3081935 Jul 4 '14 at 3:33
please consider accepting the answer :) @user3081935 – Networker Jul 4 '14 at 3:34
I don't see the regex there, let alone the PCRE. So why grep -P instead of grep -F? – Hauke Laging Jul 4 '14 at 3:37
@HaukeLaging, updated – Networker Jul 4 '14 at 3:42

If you want to use awk:

awk '/FW_6\.0\.0/ && /SUCCESS/' file
share|improve this answer
you have to escape the dots, otherwise it matches FW_6f0f0 also. – Avinash Raj Jul 4 '14 at 6:00
@AvinashRaj Good point: thank you. Updated. – jasonwryan Jul 4 '14 at 6:06


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

We don't need -P option here.

share|improve this answer

Through sed,

$ sed -n '/FW_6\.0\.0.*SUCCESS/p' file
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.