Remove blank spaces in a text file...

Hi,
I have this problem that there are blank spaces in my text file... i want to remove them

line 1
line 2
 
line 3

I want to remove the space between line 2 and line 3... I tried sed... it work but it prints the whole text file at the command prompt which i dont want....
sde i tried was like this

sed '/^[ ]*$/d' tfile

I dont want any kind of printing for sed... is there way to do this without giving an output to command prompt and just do the thing in the textfile...
Please enlight me.......Thanks

Bhagya

You want to edit the file in place, making a new version of the file.

One way:

sed '/^[ ]*$/d' tfile > tmpfile ;  mv tmpfile tfile
{rm tfile; sed '/^[ ]*$/d' > tfile; } < tfile
OR
printf '/^[ ]*$/d\n.\nwq' | ex -q tfile

Thanks a lot for helping me

Bhagya

Hi vgersh99,

I was borwsing through forum for a similar kind of a problem as bhagya had and got your reply to work
printf '/^[ ]*$/d\n.\nwq' | ex -q tfile

I would be vary grateful if you can explaing how this line works,as i am not pretty good with scripting and couldnt understand how this line works?

Thanks in advance