How to delete a specific line and the following blank line using GNU sed

sed

I have the following text:

Start-Date: 2013-11-11  07:43:49
Commandline: apt-get install --no-install-recommends catfish

Start-Date: 2013-11-11  11:27:07

Start-Date: 2013-10-16  22:53:02

Start-Date: 2013-10-16  22:55:16

Start-Date: 2013-10-17  22:41:09

Start-Date: 2013-10-17  22:42:02

Start-Date: 2013-10-17  22:42:33

Start-Date: 2013-10-17  22:46:01

Start-Date: 2013-10-17  23:00:06
Commandline: apt-get install shimmer-themes

Start-Date: 2013-10-17  23:01:52
Commandline: apt-get install --no-install-recommends gedit

I would like to delete lines beginning with "Start-Date" and the following blank line. In other words, I would like to have just:

Start-Date: 2013-11-11  07:43:49
Commandline: apt-get install --no-install-recommends catfish

Start-Date: 2013-10-17  23:00:06
Commandline: apt-get install shimmer-themes

Start-Date: 2013-10-17  23:01:52
Commandline: apt-get install --no-install-recommends gedit

I hope my question isn't a duplicate of Remove line containing certain string and the following line

Best Answer

sed '/^Start-Date:/ {N; /\n$/d}'

sed's a Stream Editor, slurp up/identify line gaggles and have your way with them.

N is "append a newline and the next input line to the current buffer", so \n in the buffer is the start of an appended line /\n$/d means "if the last appended line in the buffer is empty just drop all of it".

Related Question