Looking for a way to recursively search a repository for all files containing a multi line string and return the file names that contain it. The paragraph is just a header approx 30 lines.So I know pcregrep can do multi-line search. But you need to put the whole expression in. As this is a long paragraph I'm searching for, I want to place it in variable and just do a grep of that variable. So basically it would be find . -name *.[ch] | xargs pcregrep -M $paragraph But this does not work could anyone point me in the right direction.
Search directories for multi line string
shell script;text processing;files;diff
Since you're trying to match the first 30 lines of your files you could save the text in a file e.g. ref_file then use diff to compare the reference file with the first 30 lines in each file:find . -name *.[ch] -exec ./myscript {} \; -printwhere ./myscript is#!/bin/shhead -n 30 $1 | diff - /path/to/ref_file >/dev/nullso -print in the first command is only executed if the previous -exec evaluated true, that is if there was no difference between the reference file and the first 30 lines from the current file.Or, if you prefer without a script and saving the file names in a logfile:find . -type f -exec sh -c 'head -n 30 $0 | diff - /path/to/ref_file >/dev/null' {} \; -print >logfileNote that this assumes you're looking for an exact match otherwise diff exits with 1, even if the difference was a single space.