Remove unwanted white space

Hi,

I have a very big file 25GB with information present in it like

 
$ head ind_stats
 
update index statistics pfirm001.dbo.Office using 200 values
go
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
 

update index statistics pfirm001.dbo.States using 200 values
go
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
 
 

update index statistics pfirm001.dbo.hpsipb using 200 values
go
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 

how can i remove unwanted white spaces, keeping the spaces between words

Thanks in advance
Sam

What is on those blank lines?
Are there repeated spaces or tabs? Or simply a line-feed (new line)?

use

tr -s " "

to trim all the white spaces.

@ joeyg
I am not sure but i think those are line feeds

@ donadarsh
your code will also trim the spaces between the words of the query

Could you...

sed 's/^\n//' <infile

which would remove any line that is simply a blank line with a line-feed or return on it.

@joeyg
nope.. didn't work

In what way did it not work?

It will keep only 1 white space between each word. give a try on simple lines

echo "ABCS      asdaa     sdas ds   adasasd       sadasd"|tr -s " "

Please post a sample of the desired output.

My answer assumed the only thing on those empty lines with the new-line character. If there are spaces or tabs or any whitespace, then it would not work.
What is on those seemingly blank lines?

This should remove empty lines with any kind of whitespace..

awk NF file
1 Like

I am still getting the same output, cheked on top 10 lines of the file

 
$ head ind_stats > ghi
$ sed 's/^\n//' < ghi
 
update index statistics pfirm001.dbo.Office using 200 values
go
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
 

update index statistics pfirm001.dbo.States using 200 values
go

 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
update index statistics pfirm001.dbo.hpsipb using 200 values
go

 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 

---------- Post updated at 09:28 PM ---------- Previous update was at 09:25 PM ----------

@ Scrutinizer
awk worked perfectly!!!
Thanks

in the above post i was answering to Corona688's question on page 1, please neglect it

Many Thanks to all of you, for your prompt response