[Solved-6 Solutions] How to find patterns across multiple lines using grep - Linux Tutorial
Problem :
How to find patterns across multiple lines using grep ?
Solution 1:
You can use grep. incase you are not keen in the sequence of the pattern.
Example:
grep -l will find all the files which matches the first pattern, and xargs will grep for the second pattern.
Solution 2:
In the modern Linux systems using as
pcre2grep is available for Mac OS X
and via Homebrew as:
Solution 3:
It is simple to make:
Solution 4:
At the same line to display as 'abc' and 'efg' can be :
At different lines to display as 'abc' and 'efg' must be:
-z
Set of lines to terminated as zero
-l
print each input file as name from the output to be printed.
(?s)
activate PCRE_DOTALL, which means that '.' finds any character or newline
Solution 5:
Using p to print as simple:
Solution 6:
Using Perl.
Single regular expression an involves taking the entire contents of the file into a single string.