I have a set of txt
files whose names may contain space or special characters like #
.
I have a grep
solution grep -L "cannot have" $(grep -l "must have" *.txt)
to list all the files who have must have
but not cannot have
.
For instance, there is a file abc defg.txt
which contains only 1 line: must have
.
So normally the grep solution should find out abc defg.txt
, but it returns:
grep: abc: No such file or directory
grep: defg.txt: No such file or directory
I think for filenames containing #
, the grep solution is also invalid.
Could anyone help me amend the grep solution?
#
would not be a problem (except withzsh -o globsubst -o extendedglob
), but*
,?
,[
, space, tab, newline would be withbash
. – Stéphane Chazelas May 08 '14 at 08:46find . -type f -name \*.txt -exec grep -qF 'must have' {} \; ! -exec grep -qF 'cannot have' {} \; -print
– don_crissti Aug 19 '16 at 11:21