Remove Blank lines in VI

Hi,

Which option is used to remove blank lines in VI (AIX). ?

Regards,
Siva

Use the following options

<esc>:g/^$/d to delete blank lines that do not contain spaces.

If it contains spaces, then use <esc>:g/^ *$/d

Hi Krish,

No luck, any other options? I am using AIX VI

---------- Post updated at 09:08 AM ---------- Previous update was at 05:04 AM ----------

Hi Krish,

Apologizes, Your tip worked but I wrongly questioned for blank lines. My question is to remove blank spaces/trail spaces in a line using VI.

Regards,
Siva

You should post what you have tried.

Trail spaces like (eg only)

abcd<><><>
s/  *//g;

Hi Mathan,

No luck, not working in AIX VI.

You need to give us a suitable example of the lines with blank spaces so we can see what blanks/spaces you wish to remove.

To remove trailing spaces from all lines in your editing buffer and then remove empty lines:

:g/ *$/s///
:g/^$/d

Note that by definition, blank lines contain zero or more <space> and <tab> characters. If you have tabs in your blank lines or if you want to remove trailing blanks (instead of trailing spaces), use:

:g/[ T]*$/s///
:g/^$/d

where the T above is replaced by a tab character.