I want to print the head of a file up to a match and some lines after the match.
I know that you can use sed '/PATTERN/q' FILE
to print the file until the pattern. And sed 10q FILE
top print the first 10 lines.
Starting with this file:
lorem
ipsum
dolor
sit
amet
consectetur
adipiscing
elit
If my pattern is dolor
and I want 2 more lines the output will be:
lorem
ipsum
dolor
sit
amet
Is this a way to merge this two commands ?
Alos, is is possible to do the same for the end of the file (ie to print the tail of the file with some lines before the match) ?
If I keep the first file with the pattern amet
and the 2 lines before the match, the output will be:
dolor
sit
amet
consectetur
adipiscing
elit