Operating System - HP-UX
1753980 Members
6927 Online
108811 Solutions
New Discussion юеВ

Re: Sed problem....want to remove lines

 
Kathleen
Regular Advisor

Sed problem....want to remove lines

I am using the following sed statement

sed -e :a -e 's/<[^>]*>//g;/
When it finds and instance, its leaving a blank space in its place.
Most of the time, this is something on one line. Is there a way I can make the sed statement delete the line after the character match is removed instead of leaving a blank line? I am trying to clean-up the formatting. Thanks
3 REPLIES 3
Michael Steele_2
Honored Contributor

Re: Sed problem....want to remove lines

This will remove blank lines:

grep -v "^$" file1 > file2
cp file2 file1
Support Fatherhood - Stop Family Law
curt larson_1
Honored Contributor

Re: Sed problem....want to remove lines

you can add a
-e '/^$/d'

which will delete all blank lines from the file.

or (not so easy from the command line):
/instance pattern/ {
s/this/that/
n
d}
this makes a substitution,
n writes your change to stdout and reads the next line into the pattern buffer, d deletes that line (whatever it is)

or

n
/^$/d} to just delete the next line if it blank.
S.K. Chan
Honored Contributor

Re: Sed problem....want to remove lines

To get rid of the blank space JUST for this substitution without affecting the rest of the rest of the existing blank lines you can do this .. (a little modification to Curt's suggestion) ..

sed -e :a -e 's/<[^>]*>/=/g;/
Basically replace it with "=" and then delete that line later. That way you still retain the blank lines which are not part of this substitution. This may not be as elegant but it works.