grep: searching for pipes, optional characters
Posted by jpluimers on 2016/09/22
For my own reference as RegEx is a write-only language:
Search for pipes means just back-slash escaping them:
grep "\|S\|" products.txt > s-rated-products.txt
Search for optional charactes (in this case searching for both the singular and plural form of a word) can be done by grouping the optional part in parentheses:
grep -i "Movie(s)?" products.txt > movie-products.txt
Search for either OR:
grep -E "foo|bar" products.txt > foo-or-bar-products.txt
egrep "foo|bar" products.txt > foo-or-bar-products.txt
Note that the Borland grep does not support the OR syntax, but egrep does.
–jeroen
via:






Leave a comment