bash grep newline


Question

[Editorial insertion: Possible duplicate of the same poster's earlier question?]

Hi, I need to extract from the file:

first
second
third

using the grep command, the following line:

second
third

How should the grep command look like?

1
11
5/23/2017 10:29:24 AM

Instead of grep, you can use pcregrep which supports multiline patterns

pcregrep -M 'second\nthird' file

-M allows the pattern to match more than one line.

20
8/4/2009 6:29:57 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon