Reputation: 10470
I need to search a large group of data files. I want to find files that contain the string "foo\tbar\tboo". I have tried this ...
$ find . -name "foo*dat" -exec grep foo {} \; | less
"miscinfo_foo" => [
"foo\tbar\tnot_foo"
"miscinfo_foo",
"miscinfo_foo" => [
"foo\tbar\tyes_foo"
"miscinfo_foo",
But if I do ...
$ find . -name "foo*dat" -exec grep -E "foo\tbar" {} \;
... I get no output. I have tried egrep too. I have tried escaping the \t
with \\t
but still get no output.
What am I doing wrong?
Thanks
Upvotes: 2
Views: 112
Reputation: 74685
There are two effects at play here:
\t
means a tab character.\\
to \
within a double-quoted string.You want the slash to be escaped, so you need to pass \\t
to grep within single quotes:
grep 'foo\\tbar'
Upvotes: 1
Reputation: 17051
Try
find . -name "foo*dat" -exec grep -E 'foo\\tbar' {} \;
^ ^ ^
in single quotes rather than double, and with an extra backslash. The ''
prevent bash
from processing backslashes, so that grep
will actually see foo\\tbar
. Based on your output, I think you are looking for the literal text backslash-tee, not an ASCII character 9, so double the backslash to have grep
match it as literal text.
Upvotes: 2