Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!bloom-beacon!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.questions Subject: Re: does vi have a search/deletion macro??? Message-ID: <14154@bloom-beacon.MIT.EDU> Date: 8 Sep 89 18:50:25 GMT References: <20802@adm.BRL.MIL> <5285@ucdavis.ucdavis.edu> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: jik@athena.mit.edu (Jonathan I. Kamens) Organization: Massachusetts Institute of Technology Lines: 66 In article <5285@ucdavis.ucdavis.edu> lee@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@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@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-4261 Home: 617-782-0710