Here is my one-liner:
sed -n '/BEGIN/,/END/{$d;1d;p}' query
And query:
trash BEGIN first labas END nieko nėra BEGIN second iki END nesimato
I expect this result:
labas iki
However, I get this:
BEGIN first labas END BEGIN second iki END
What do I misunderstand about sed context? Shouldn’t {$d,1d;p} delete first and last line of the matching input?
No, it deletes any line of the matching input that is the first or last line of the file. You can see the effect if you remove the first two lines of
query(so that the first line is “BEGIN”).