Thursday, December 29, 2011

Removing mutlitple spaces in a file with single space in Linux

Folks, it is time for some Linux commands.

Ok. Here is the one that I have used, to remove lot of spaces between words with a single space in a file.

cat MoreSpaces.txt | tr -s ' ' ' ' > OneSpace.txt

For example the "MoreSpaces.txt file is having the following text.

"Hello          This is      having      more spaces        between words..."

So, once you execute the above command the output file "OneSpace.txt" will be created and it's contents will be like as given below.

"Hello This is having more spaces between words..."

Sweet isn't it ???





No comments:

Post a Comment