0

I have a directory with the following files:

foo.bar.1.txt
foo.bar.2.txt
foo.bar.1.out
foo.bar.2.out
bar.1.txt
bar.2.txt
bar.1.out
bar.2.out

I have two goals:

Primary: In a script, I'd like to cat bar.2.out (but not foo.bar.2.out) but the "bar" varies from case to case. In other words, I really want it to cat *.2.out, excluding the foo.bar.2.out file.

Secondary: Learn more about how extended globbing works. I understand that I could probably use some combination of find and grep to filter for the file I want.

William Everett
  • 751
  • 1
  • 8
  • 18

1 Answers1

2

Yes, extended globbing should do it.

$ shopt -s extglob
$ ls !(foo*).2.out
bar.2.out
choroba
  • 231,213
  • 25
  • 204
  • 289
  • Well, that worked but I'm not sure why. Does the !(foo*) basically act as a wildcard excluding anything that starts with foo? Also, since there's a * after foo, why doesn't it exclude bar.2.out since foo is used 0 times there? – William Everett Feb 15 '13 at 15:58