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,527
  • 2
  • 17
  • 33

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'
Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
cuonglm
  • 150,973
  • 38
  • 327
  • 406