Thursday, January 17, 2008

HowTo: Remove Tabs From Text Files Completely

Here's how to remove tabs or tab characters completely from a file.

# cat testfile.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a a a a
b b b b
c c c c
123 123 123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Let us be verbosed and show tab characters when viewing text files
# cat -t -v testfile.txt
~~~~~~~~~~~~~~~~~~~~~~
a^Ia^Ia^Ia
b^Ib^Ib^Ib
c^Ic^Ic^Ic
123^I^I123^I^I123
~~~~~~~~~~~~~~~~~~~~~~

From the above result, the tab chacters are represented by (^I) characters. To remove these tab characters, simply

# cat testfile.txt | tr -d "\t\v"
~~~~~~~~~~~
aaaa
bbbb
cccc
123123123
~~~~~~~~~~~

Saved it permanently
# cat testfile.txt | tr -d "\t\v" > testfile-NO-TABS.txt


Related Reading:
Replacing Tab with Space Character
Remove Space from Filenames
Remove Blank or Empty Lines from File Using sed or grep

0 comments:

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