Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

Thank you soo much James...it worked like a champ. Great!!!
Note: Honestly... I could not understand what exactly the "!b" stands for. :))

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.

James,
Believe me ...You are a perfect teacher!!!
Can't be adequately thankful to you for your help.
Thank you soo... much.

![]() |
Solaris 9 and .profile
|
Solaris pkgadd problem
|

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