I have a file with this content:
$ cat compromised_header.txt
some unique string 1
some other unique string 2
another unique string 3
I wanted to find all files that have all the lines of above file exactly in the same order and those lines have no intermediary lines in between.
Example input file:
$ cat a-compromised-file.txt
some unique string 1
some other unique string 2
another unique string 3
unrelated line x
unrelated line y
unrelated line z
I tried using below grep
:
grep -rlf compromised_header.txt dir/
But I wasn't sure it will give the expected files as it will also match this file:
some unique string 1
unrelated line x
unrelated line y
unrelated line z
Best Answer
Using an awk that supports
nextfile
:with
find
for recursion:Or this might work:
Using perl to escape metacharacters because pcregrep doesn't seem to combine
--fixed-strings
with--multiline
.With perl in slurp mode (won't work with files that are too large to hold in memory):