Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.