Computing.Net > Forums > Unix > Deleting Empty lines using sed

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Deleting Empty lines using sed

Reply to Message Icon

Name: sree06
Date: November 29, 2006 at 12:42:43 Pacific
OS: Solaris 9
CPU/Ram: Unknown
Product: SUN micro
Comment:

Hi Guys,

Someone help me with this?

How to delete all the empty lines... between the lines staring with ABC and XYZ using sed?

I tried the following, but didn't work:

sed '/^ABC/,/^XYZ/ /^$/ d' file_1 > file_2

Thanks in advance.
-sri



Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: November 29, 2006 at 15:19:19 Pacific
Reply:

sed -e /^ABC/,/^XYZ/!b -e /^$/d file_1 > file_2


0

Response Number 2
Name: sree06
Date: November 29, 2006 at 16:48:04 Pacific
Reply:

Thank you soo much James...it worked like a champ. Great!!!

Note: Honestly... I could not understand what exactly the "!b" stands for. :))


0

Response Number 3
Name: James Boothe
Date: November 30, 2006 at 08:01:46 Pacific
Reply:

A b command branches to the specified label, or if no label is specified (as in this case), it branches to end_of_line processing, at which point it will output the current buffer if it has not been deleted and if the -n option has not been specified.

The ! is a negator. The command /xyz/d would delete lines containing xyz, and /xyz/!d would delete lines that do NOT contain xyz.

So the first command says if this is a line that is NOT between the ABC and XYZ lines, then branch to end-of-line processing, at which point that line would be sent to output.

For lines that ARE between ABC and XYZ, the logic will not branch, but instead will advance to the next command which will delete the buffer if it is empty. If the line is not empty, it falls into to end-of-line processing where the buffer will be sent to output.


0

Response Number 4
Name: sree06
Date: December 1, 2006 at 01:26:31 Pacific
Reply:

James,

Believe me ...You are a perfect teacher!!!

Can't be adequately thankful to you for your help.

Thank you soo... much.


0

Response Number 5
Name: James Boothe
Date: December 1, 2006 at 07:11:01 Pacific
Reply:

You are too kind. Next year, you will be the teacher.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

Solaris 9 and .profile Solaris pkgadd problem



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Deleting Empty lines using sed

Deleting multiples lines in one SED www.computing.net/answers/unix/deleting-multiples-lines-in-one-sed/7517.html

Delete first line of a file www.computing.net/answers/unix/delete-first-line-of-a-file/7594.html

using sed www.computing.net/answers/unix/using-sed/4164.html