You're replying to a comment by RenaudD.

RenaudD Permalink
October 08, 2008, 23:57

I am a sed addict and your nice site won't help me to cure. I love the

sed -n '$='

:).
Maybe this will interest you :
Sometimes you have to print blocks of lines that contains a special string. For instance if filename contains :

foo
baz
bar

bar
foo

goo
baz

and you would like to get only the blocks that contain 'baz' that is :

foo
baz
bar

goo
baz

I do sthg close to it that way :

sed -n 'H;/^$/x;/baz.*\n/p' filename

I said 'close to it' because unfortunately this command prints a bit too many empty lines before the selected blocks but generally I don't mind. Anyway if you find a way to straighten it I would be delighted to know it.

Note : you have to make sure the last line of filename is an empty line otherwise the last block won't be processed :(

Thanks again for the site !

PS sorry I am not very talented for HTML, I hope all this will print correctly

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "quake3_95": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.