using vi -c to remove empty lines

Hello:

I searched here for "vi -c" but found no hits.
How can I use vi -c to remove ALL empty lines, regardless of how many?

I tried
<code>
vi -c ":g/^$/d | wq" filename
</code>
but I have to run it several times.

This is NOT homework. :slight_smile:

Thanks for your time.

If you just want to remove empty lines, you can simply use grep.
The following one liner removes all empty lines(those contains spaces, tabs, or nothing) in a file.

grep -E '[^   ]+$' filename

Try running the commands using two -c options on the command line:

vi -c "g/^$/d" -c "wq"   file2edit

agama wins the prize!
1 ABP. :cool:
Thanks!