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?

030
  • 1,557

1 Answers1

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'
cuonglm
  • 153,898