Thursday, April 29, 2010

Control characters in source file after ftp

<p align="justify">My friend had a problem with a Linux file. he had ftp'd a file from windows into Linux. Now, every line in that file has a ^M at its end. He wanted a way to avoid it, and/or remove the control characters from such files.

Browsing thru the web, there were multiple answers provided.

1. While uploading via ftp, use the ASCII mode, not the binary mode. This will translate the line ends properly. Binary mode is to be used for programs and archive files only (like zip, tar, etc..)
2. dos2unix (and its complementary unix2dos utility)
3. cat file | tr -d "\r" > newfile
4. sed 's/.$//' infile.txt > outfile.txt
5. col -bx < oldfile > newfile

Disclaimer: I have not tried this in any of the ways mentioned. I am just listing it for easy access only.</p>