Crouching tr, Hidden CRLF

Hundreds of articles on the Internet address this and many spend their time seeking these out. Here is on

e more, with examples cribbed from someone else, so that a search engine picks it up and helps someone else.

In Unix, the character transliteration tool 'tr' exists almost from the beginning.

To remove CR=13(dec)=15(oct)

$ tr -d '\015' < infile.txt outfile.txt

To remove LF=NL=10(dec)=12(oct)

$ tr -d '\012' < infile.txt outfile.txt

To remove both:

$ tr -d '\015\012' < infile.txt outfile.txt

... all just from the command line, no programming. You can also transliterate other characters, of course, for instance a->d, b->e, c->f by

$ tr 'a-c' 'd-f' < infile.txt outfile.txt

In Linux, there will be mnemonics for meaningful character subsets like '[:cntrl:]' and '[: punct:]' Here are some methods to display the characters With sed

$ sed -n 'l'

From within vi

  :set list

With cat

$ cat -v infile.txt

The file command can be used to check in many cases

$ file infile.txt outfile.txt
infile.txt:       ASCII mail text, with CR, LF line terminators
outfile.txt:      ASCII mail text