Reputation: 4980
If I use --exclude-from
multiple times (to include multiple files), will grep
just use the last --exclude-from
or will it "or" all the filters together as if they had been in one file (and using one --exclude-from
)?
Upvotes: 2
Views: 887
Reputation: 31
Although this is not clear from either the man pages or grep's source code, exclude-from is additive. Here's my example:
Make five files named 'file.a' through 'file.f' each containing 'test_string', and five filters 'ex_a.lst' through 'ex_f.lst' containing '*.a' through '*.f', respectively:
$ for X in a b c d e f; do echo test_string > file.$X; echo file.$X > ex_$X.lst; done
$ ls -l
total 48
-rw-rw-r-- 1 user group 7 Jan 17 17:02 ex_a.lst
-rw-rw-r-- 1 user group 7 Jan 17 17:02 ex_b.lst
-rw-rw-r-- 1 user group 7 Jan 17 17:02 ex_c.lst
-rw-rw-r-- 1 user group 7 Jan 17 17:02 ex_d.lst
-rw-rw-r-- 1 user group 7 Jan 17 17:02 ex_e.lst
-rw-rw-r-- 1 user group 7 Jan 17 17:02 ex_f.lst
-rw-rw-r-- 1 user group 12 Jan 17 17:02 file.a
-rw-rw-r-- 1 user group 12 Jan 17 17:02 file.b
-rw-rw-r-- 1 user group 12 Jan 17 17:02 file.c
-rw-rw-r-- 1 user group 12 Jan 17 17:02 file.d
-rw-rw-r-- 1 user group 12 Jan 17 17:02 file.e
-rw-rw-r-- 1 user group 12 Jan 17 17:02 file.f
$ cat file.a
test_string
$ cat ex_a.lst
file.a
Search for 'test_string' in the current directory, without filters:
$ grep -R test_string | sort
file.a:test_string
file.b:test_string
file.c:test_string
file.d:test_string
file.e:test_string
file.f:test_string
All files matched. Now add three filters from three files:
$ grep -R test_string --exclude-from=ex_a.lst --exclude-from=ex_c.lst --exclude-from=ex_e.lst | sort
file.b:test_string
file.d:test_string
file.f:test_string
We are left with only three results, the ones that weren't filtered out! For this to be the case, we must have selected all three 'ex_[ace].lst' filter files.
Upvotes: 3