Question:
How could I find matches of a multi-line regular expression in files, without pcregrep?
I need to find/print the position of each occurrence.
Unfortunately, pcregrep is not present and I have no rights to install it. Other alternatives are grep
perl
sed
python
etc.
An example of regular expression to search is:
Text\nLine
Context:
A script provides hundreds MB of structured text in a few tens of files, but unfortunately some lines are missing (due to many reasons). I do need to check where those lines are missing, thus searching for the sequence of the previous and following lines.
Text
Missing //this line is sometimes missing.
Line
EDITED:
Possible input
example.txt
Text
Missing
Line
Text
Missing
Line
Text
Line
Text
Missing
Line
Possible output:
example.txt, line 10
Some of the tries with no success:
pcregrep
# command not found
apt-get install pcregrep
# no permission, no su credentials, distro don't provide pcregrep, outdated sources, customer does not want changes on the serve, etc.
sed -r 's#(Text\nLine)#\1#' ./*
# print all lines, not only matches, no indication of file or line, etc.
grep 'Text\nLine' ./*
# Does not works on multi-lines
sed -n '/Text/,/Line/{p}' ./*
# Not the same regex, does not indicate result lines, etc.
Text\r?\nLine
– Adrian Maire Jun 11 '18 at 07:49