Operating System - HP-UX
1833679 Members
4406 Online
110062 Solutions
New Discussion

Delete empty lines in vi .

 
SOLVED
Go to solution
chapaya_1
Frequent Advisor

Delete empty lines in vi .

Hi ,

I have a file with a lot of empty lines ,
how do i delete them all ?

BYE.
6 REPLIES 6
Shaikh Imran
Honored Contributor

Re: Delete empty lines in vi .

Hi,
Follow this link for all you vi queries.
http://www.vmunix.com/~gabor/vi.html

For this query use
Eec
:g/^[ ^I]*$/d
First check this in a test file

Regards,

I'll sleep when i am dead.
chapaya_1
Frequent Advisor

Re: Delete empty lines in vi .

Hi Shaikh ,

It's not working .

Bye.

Jeroen Peereboom
Honored Contributor
Solution

Re: Delete empty lines in vi .

If the lines are really empty (no spaces or tabs):
:g/^$/d

Otherwises:
:g/^[ X]*$/d
where X is a TAB character which is difficult to type in the forum.

You may want to use sed i.s.o. of vi.

JP
H.Merijn Brand (procura
Honored Contributor

Re: Delete empty lines in vi .

And to add an alternative:

# perl -pi -e's/^\s*$/ and$_=""' file

will delete all lines in file "file" that have only blanks

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Bill Hassell
Honored Contributor

Re: Delete empty lines in vi .

Somewhat esoteric commands, but here is a really simple method:

rmnl | ssp >



Bill Hassell, sysadmin
KapilRaj
Honored Contributor

Re: Delete empty lines in vi .

cat filename |grep -v "^$" > newfile

Kaps
Nothing is impossible