1

If packagehello does not match, the output is still displayed.

Aim: to see no output in situation 2

Situation 1:

user@hostname ~]$ sudo yum list 'package*'
packagehello
packagehello
package2world
packagehello
package2world

Situation 2:

user@hostname ~]$ sudo yum list 'package*' | grep -E 'package1.*|package2.*'
package2world
package2world

How to show the output only if both words match using grep?

2
  • 1
    packagehello matches neither package1.* not package2.*. Are you sure of your output? Commented Jun 25, 2014 at 15:03
  • Question has been updated. The expectation is to see no output in situation 2. Commented Jun 25, 2014 at 15:07

1 Answer 1

2

Try this:

sudo yum list 'package*' |
  grep -E 'package1.*package2|package2.*package1'

or using multiple grep:

sudo yum list 'package*' |
  grep 'package1' |
  grep 'package2'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.