does vi have a search/deletion macro???

Jonathan I. Kamens jik at athena.mit.edu
Sat Sep 9 04:50:25 AEST 1989


In article <5285 at ucdavis.ucdavis.edu> lee at iris.ucdavis.EDU (Peng Lee) writes:
>I have a similar question:  How do you delete a empty line using "sed"
>or "ed" ?  I have try the 'sed -e "/^$/d" filename ', but it doesn't work.
>
>-Thanx
>Peng (lee at iris.ucdavis.edu)

  If the lines are really blank, that will work.  However, they will
often contain tabs or spaces in them.  Therefore, what you should use
is "sed -e '/^[ ^I]*$/d' filename" (the ^I is a real tab character).
Watch this:

Script started on Fri Sep  8 14:44:19 1989
vulcan% cat test
This is a test file.
There is a blank line here:

Here's a line with a space on it:
 
And here's one with a tab on it:
        
And here's one with a space and a tab:
        
And this is the end of the file.
vulcan% sed '/^$/d' test
This is a test file.
There is a blank line here:
Here's a line with a space on it:
 
And here's one with a tab on it:
        
And here's one with a space and a tab:
        
And this is the end of the file.
vulcan% sed '/^[ ]*$/d' test
This is a test file.
There is a blank line here:
Here's a line with a space on it:
And here's one with a tab on it:
        
And here's one with a space and a tab:
        
And this is the end of the file.
vulcan% sed '/^[^I]*$/d' test
This is a test file.
There is a blank line here:
Here's a line with a space on it:
 
And here's one with a tab on it:
And here's one with a space and a tab:
        
And this is the end of the file.
vulcan% sed '/^[ ^I]*$d/' test
This is a test file.
There is a blank line here:
Here's a line with a space on it:
And here's one with a tab on it:
And here's one with a space and a tab:
And this is the end of the file.
vulcan% exit
script done on Fri Sep  8 14:45:24 1989

Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-4261			      Home: 617-782-0710



More information about the Comp.unix.questions mailing list