Removing blank lines or replacing white spaces in a file

>> Monday 24 December 2018

in vim:

:g/^$/d


:  put into a state for editing with regex commands

g for every line in the file

/  let's start

^  from the start of the line

$   to the end of the line (^$ together is a special instruction that says blank line)

/ next instruction

d delete it




with vi

 :g/^[ ]*$/d

there's a space in between those square brackets 

vim

:g/^\s$/d

\s means white spaces

remove blank lines from a file with sed:
sed -i '/^$/d' myfile.txt


Replace white spaces with commas:
:%s/\s\+/,/g

replace a word in vi

:g;myword;s;;replaceitwiththis;g

For replacing a word after a word see this post
Here is a useful link for regex expressions:


for vim:



0 comments:


  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP