Page tree
Skip to end of metadata
Go to start of metadata

Using OR Operator

Sample file,

cat fruits.txt
yellow bananas
green apples
red oranges
red apples

Using OR operator in grep search. Note you need a somewhat current version of grep (you are out of luck with Solaris use egrep for Solaris),

grep 'apples\|oranges' fruits.txt
green apples
red oranges
red apples

Grep for items that do not match,

grep -v 'read' fruits.txt
yellow bananas
green apples

Have grep tell you if it found a match in the file,

grep "diddle" -q fruits.txt && echo "FOUND" || echo "NOPE"
NOPE
grep "apples" -q fruits.txt && echo "FOUND" || echo "NOPE"
FOUND

Look up if time permits how to do this using quotes to handle spaces or special characters....

Hmm, maybe all I need to do is escape any special characters and spaces probably work as is.

  • No labels