Logical OR in GLOB during grep - include / exclude

In Ubuntu terminal, I would like grep

all files with extension (or excluding) .foo

and .bar

for the phrase 'foobar'

.

I read this advice for creating GLOB

with boolean or, and tried several combinations, but none of them work:

rgrep "foobar" --include "*.foo|*.bar"
rgrep "foobar" --include "*.{foo,bar}"
rgrep "foobar" --exclude "(*.foo|*.bar)"

      

What's the secret recipe?

+3


source to share


1 answer


You can use a template here extglob

:

shopt -s extglob
grep 'foobar' *.@(foo|bar)

      




To use recursive grep with --include

you only need to use GLOB templates :

grep -R 'foobar' --include=*.{foo,bar} .

      

+4


source







All Articles