Today I’ve downloaded a text file and I’ve found a lot of CTRL+M (15 octal character) garbage characters. This could be caused by a mistake when downloading the file with FTP bin mode enabled… who knows…
Anyway, our friend the tr command is here to help…
tr, as the man page tells, translates or deletes characters. If you want to delete those characters try this:
tr -d ‘\15′ < annoying_file.txt > clean_file.txt
Be careful! The above command will delete the CTRL+M characters. It’s better to substitute them by line breaks:
tr ‘\15′ ‘\12′ < annoying_file.txt > clean_file.txt
If you want to delete the original file…
tr ‘\15′ ‘\12′ < annoying_file.txt > clean_file.txt && rm annoying_file.txt

