Strip ^M Characters from Files

Because I regularly move between operating systems, I often need to use Windows-created files on Linux. Because of the difference in EOL notation between the operating systems (notice how I carefully avoided any editorial comment on that difference?), that means regularly encountering the ^M character.

While I’ve never found a situation where the character creates a real problem for me, it’s certainly annoying to see those things all over a large file. In the past I’ve used elbow grease and/or various shell scripts to clear these, but today I found out that Ubuntu (probably other distros, as well) offers a utility to do this quickly and easily.

The package is named tofrodos and, while not installed by default, is available in the repository. To install & use:

$ sudo apt-get install tofrodos
$ dos2unix <file to convert>

Couldn’t be easier, right? This is the thing I love best about Linux.

Subscribe2 Comments on Strip ^M Characters from Files

  1. Matt said...

    I believe the package is actually tofrodos. No ‘m’ there.

  2. Rob Wilkerson said...

    Yeah, when you caught this, I was merely making a note that I intended to save as a draft. I realized I hadn’t done so when it popped up in my reader so I’ve now finished the post (albeit hastily) with your correction.

    Thanks.