Conditional Multi-Line Grep Problem

Hi, I have a very large file I want to extract lines from. I'm hoping Grep can do the job, but I'm running into problems.

I want to return all lines that match a pattern. However, if the following line of a matched line contains the word "Raw" I want to return that line as well.

Is this doable?

For example,

Input:

pattern blah blah blah
something nothing
pattern something ready
nothing Raw

A grep on "pattern" should return:

pattern blah blah blah
pattern something ready
nothing Raw

Because the line "pattern something ready" is followed by a line containing "Raw", "nothing Raw" is also included.

Thanks

Please post a sample of your input and an example of the expected output.

Is this what you want:

sed -n -e '/pattern/p' -e '/pattern/{n;/Raw/p;}' Input_File
1 Like

That works. As an aside, how would I edit that command to handle the situation where there is a blank line between each line in the input file? Thanks