Take the following file :
$ cat f1
stu vwx yza
uvw xyz abc
abc def ghi
def ghi jkl
ghi jkl mno
jkl mno pqr
mno pqr stu
pqr stu vwx
stu vwx yza
To print all lines from the first one containing abc to the first one containing mno with GNU sed :
$ sed -n '/abc/,/mno/p' f1
uvw xyz abc
abc def ghi
def ghi jkl
ghi jkl mno
How could I print all lines until the last one containing mno, e.g. how could I get the following result :
uvw xyz abc
abc def ghi
def ghi jkl
ghi jkl mno
jkl mno pqr
mno pqr stu
In other words, is there a way to make GNU sed's range selection greedy ?
Update
In my setting :
- If
mnois missing, it should print out everything until the end of the file. mnocannot occur before the firstabc.- There's always at least one
abc, andabcandmnoare never on the same line
EDIT
I just added a dummy stu vwx yza line at the start, so that the file doesn't start with a line including abc (to avoid solutions that start from the first line - they should start from the first line having abc in it)