sed show lines text between 2 blank lines

I have a file like

blah
blah blah blah

this is the text I need,
which might be between 1-4 lines, but
always has a blank line above and below
it, and is at the end of the text file


the code tags don't show the trailing blank line. I started by deleting the last blank line with:

sed -i '$d' textfile

but how to I get sed to give me the next 1-4 lines above that output to somenewfile.txt, but stop at the next blank line above it?

If the posted last line is the eof then try

sed '/^$/,/^$/!d' inputfile > outfile.txt
1 Like

hey, thanks, that worked :slight_smile:

So now, I guess ^$ represents a blank line, but how does the command determine what part of the file to start looking, i.e. I'm just trying to understand what sed is doing a bit better.