Saturday, 28 February 2015

vi

Remove leading white space in vi editor:
------------------------------------------------------------

Well it sounds very simple, but thought would be useful for all vi newbies :-)

This is how we can remove all leading white space(s) from all lines in vi editor:


In ex mode:


:1,$ s/^\s*//g


Delete blank lines in vi editor:
-----------------------------------------------

Simple but useful vi editor tip.

Q. How can I delete any blank lines within a file in vi editor?

Ans:
In escape mode type

:g/^$/ d

And all your blank lines should be removed !!

Other ways of removing blank lines from a file using grep, awk and sed

$ grep -v '^$' file
$ grep '.' file
$ sed '/^$/d' file
$ sed -n '/^$/!p' file
$ awk NF file
$ awk '/./‘ file

No comments:

Post a Comment