Friday, January 18, 2008

HowTo: Delete Extra Spaces Between Words From Files

Have you encountered a text file full of words separated by multiple extra space between words? Mostly, these files are caused by data export mechanism by some application processing software.

Now, here's how to remove and delete those multiple and extra spaces between words of a file.

# cat testfile.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tomboy is a desktop note-taking application for Linux and Unix. Simple and easy to use, but with potential to help you organize the ideas and information you deal with every day.

Tomboy usefulness lies in the ability to relate notes and ideas together, using a WikiWiki-like linking system.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here's its equivalent captured image of the above testfile.txt as blogger would definitely remove thos cluttered space characters in between the above words. To have a wider view of the testfile with extra space, see below image.



Now, let us remove those multiple cluttered spaces in between words.

# cat testfile.txt | tr -s " "

Alternatively

# tr -s " " < testfile.txt

Result:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tomboy is a desktop note-taking application for Linux and Unix. Simple and easy to use, but with potential to help you organize the ideas and information you deal with every day.

Tomboy usefulness lies in the ability to relate notes and ideas together, using a WikiWiki-like linking system.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Congrats, you have now suppressed multiple extra space between words of a text file.

Enjoy.

Related Readings:
Tr Linux Command Explained
Remove Space Character from Filenames

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy