4

In the Ubuntu terminal, I would like to grep all files with (or excluding) extension .foo and .bar for the phrase 'foobar'.

I've read this advice for creating a GLOB with a logical or, and tried a few combinations but none seem to work:

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

What's the secret recipe?

LondonRob
  • 73,083
  • 37
  • 144
  • 201

1 Answers1

5

You can use extglob pattern here:

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

For using recursive grep with --include you have to use GLOB patterns only:

grep -R 'foobar' --include=*.{foo,bar} .
anubhava
  • 761,203
  • 64
  • 569
  • 643