Tuesday, September 25, 2007

deleting new lines and return line from text file

How to delete new lines and return key characters from text file?
How to delete backspace and formfeed characters from text file?
How to delete horizontal tab and vertical tab character from text file?
How to remove backslash from text file?
How to delete specific set of characters from text file?

A sample text file.

# cat testfile.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The quick brown fox blogs over the Linux SysAd.



The quick brown fox blogs over the Linux SysAd.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To delete new lines and empty lines from text file
# tr -d '\n' < testfile.txt

How to delete backspace and form feed characters from text file?
# td -d '\b' < testfile.txt
# td -d '\f' < testfile.txt
# td -d '\b\f' < testfile.txt

How to delete horizontal tab and vertical tab character from text file?
# td -d '\t' < testfile.txt
# td -d '\v' < testfile.txt
# td -d '\t\v' < testfile.txt

How to remove backslash from text file?
# cat testfile.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The quick brown fox blogs over the Linux SysAd.
\
\\
\\\
The quick brown fox blogs over the Linux SysAd.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# td -d '\\' < testfile.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The quick brown fox blogs over the Linux SysAd.



The quick brown fox blogs over the Linux SysAd.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


How to delete specific set of characters from text file?
# cat testfile.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The quick brown fox blogs over the Linux SysAd.



The quick brown fox blogs over the Linux SysAd.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# tr -d '=aeiou=' < testfile.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Th qck brwn fx blgs vr th Lnx SysAd.



Th qck brwn fx blgs vr th Lnx SysAd.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


For more string and character manipulation of text file, read more tr arguments from here.

0 comments:

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