How do I find files containing some particular text containing newlines and plenty of other charachters all sorts of quotes and backslashes using terminal?
Asked
Active
Viewed 131 times
0
-
may be you should take a look at man pages of `egrep` to search with regular expression. As I do not know what exactly you're searching for, I can tell you this `find /dir -type f | xargs egrep '---' Replace `'---'` with actual regex – Soumyadip DM Aug 29 '15 at 17:28
-
The problem is the search pattern is way too big for this. Specifically it's a piece of html code. Tried grep -F, but the passage contains non-unique lines, so the output is messy. – Maxim Vasilyev Aug 29 '15 at 17:44
1 Answers
1
grep
is somewhat line-based, so matching across line boundaries might be problematic with it. If you've the memory to spare, match against the whole file with e.g. perl
:
$ (echo fish; echo cat; echo dog; echo frog) \
| perl -0777 -nE 'say $1 if m/(cat.dog)/s'
The "all sorts of quotes and backslashes" bit will likely mostly be avoiding shell interpolation rules, e.g. via '\''
type tricks or see ascii(7)
and then in perl use an appropriate \047
or \x52
or whatever as necessary. Lacking the memory to load the file, strings(1)
might first be used to reduce the amount of data to search.

thrig
- 1,676
- 11
- 9