Ausgabe nur anzeigen, wenn beide Wörter mit grep übereinstimmen

Ausgabe nur anzeigen, wenn beide Wörter mit grep übereinstimmen

Wenn packagehellokeine Übereinstimmung vorliegt, wird die Ausgabe trotzdem angezeigt.

Ziel:zu sehen no outputin 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

Wie zeigt man in der Ausgabe an, dass only ifbeide Wörter mit übereinstimmen grep?

Antwort1

Versuche dies:

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

oder mit mehreren grep:

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

verwandte Informationen