0

How do I find files containing some particular text containing newlines and plenty of other charachters all sorts of quotes and backslashes using terminal?

2
  • 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 Commented Aug 29, 2015 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. Commented Aug 29, 2015 at 17:44

1 Answer 1

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.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.