Sed/Awk - pull lines between pattern x and y

awk, bash, sed

Solution

Using `awk` it's pretty straightforward:

awk '/Header/ { show=1 } show; /Footer/ { show=0 }'

Basically keep state in a variable named `show`. When we hit the Header we turn it on, Footer we turn it off. While it's on, the `show` rule executes the default action of printing the record.

Problem

I've got some large CSV files where I'd like to extract all data between Line X that includes pattern 'x' and Line Y that includes pattern 'y' For example: ``` other_data Header data data data Footer other_data ``` I want to be able to pipe everything between (and including) Header -> Footer to a new file. Thanks!

Original source