Tired of removing ^M by hand?

Moving files from Windows to UNIX or Linux (and now MacOSX) can be a pain if during the process you end up with a text file full of EOL characters thanks to how Microsoft terminates lines of text in Windows.  Yep, that’s the little ^M at the end of every line.  Sometimes, no matter how hard you try, you can’t help but get stuck with them.

Here’s a tip for getting rid of them once and for all.  Use the dos2unix command!  Just like it sounds, it converts text files riddled with ^M’s to nice pretty *nix happy files.

By default, the command will open and read your file, and write it back to it’s original name and location.  Minus the ^M beasties.  So you can simply do this to convert a file:

dos2unix filename

Yes, it’s that easy.  There are other options if you want to get fancy, read the man page it’s full of information.  Do a quick Google search and you’ll find lots of resources about it, but chances are it’s already part of your Linux distro.  Other operating systems may be different.  Have fun!

Tell me what you are thinking?