MYSYSAD.COM

Delete Tabs, Newlines, Carriage Returns, or Spaces from a File

· Shell & text · Files & disks

There are times when you might want to delete formatting characters from a file. The tr command does an excellent job of performing this task. Here are some examples.

Note: I have included a screen shot of this task per the request of a commenter. This example in the jpeg deals with tabs and newlines.

Remove tabs
# more filename
esoft esoft esoft
esoft esoft esoft

# cat filename | tr -d space '\t'
esoftesoftesoft
esoftesoftesoft
# tr -d space '\t' < filename

Remove newlines
# cat filename | tr -d space '\n'
esoft esoft esoftesoft esoft esoft




Additional information:
Remove carriage returns
# cat filename | tr -d space '\r'

Remove spaces
# cat filename | tr -d space "space"