2

I need to extract log data from many terrabytes worth of log files. The thing is, the data I need starts and ends with patterns I can identify, but the code between can be anything between 10 and 100+ lines.

Example:

Start
# lots of lines here
End

Currently, what I do is grep -A 50 "Start", which gives me the Start and the 50 lines thereafter. However, in almost all cases that is more or less than I need. More meaning the resulting report file grows Gigabytes larger than it needs to be and less meaning I don't get the information I need.

Is there a way to extract exactly what I need, using standard Unix / Linux tools?

1 Answers1

4

Try it with awk:

awk '/^Start/,/^End/' file

or if you prefer sed:

sed -n '/Start/,/End/p' file
Simon
  • 3,973