Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

is there some way to filter output of command by OR condition in Linux?
There is filtering by AND condition with grep in way like:

ls -l | grep "^a" | grep "z$"

That says: list all files that beggins with "a" AND ends with "z" (so there is shorter way to write this: grep "^a\.*z$", but it is not matter).
Is there some way to perform test by OR condition?
For example: files that starts exactly with "xen" OR files that ends exactly with ".rpm". But exactly, not something like:

grep "[xen]{0,3}\.*[.rpm]{0,4}"

Thank you for ahead.

share|improve this question
up vote 4 down vote accepted

GNU grep accepts \| as an OR operator in regular expressions, so you could use

grep '^xen\|\.rpm$'
share|improve this answer

You can use egrep (which is an alias for grep -E) to use extended regular expressions in the search pattern like this:

egrep '^xen|\.rpm$'

Note that [xen]{0,3} means: Look for a string that has a length between 0 and 3 and consists of any combination of the characters x, e and n.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .