Monday, January 25, 2010

dos to *nix text file

One of annoyances when working in both Windows and Linux OS is the different format of the text files created.
In Linux OS, when you open a text file (using vi) which happened to be created within Windows OS, you will see a lot of "^M" character. Really annoying.

In the past I used dos2unix to convert, but I don't use it anymore since I could just use sed, instead.

Here's the command.

$ sed -i -e 's/\r//g' file_name


To make it even easier, I created a shell script which contain that command, like the following:

#!/bin/bash
sed -i -e 's/\r//g' $*


... and you're ready to go.

No comments:

Post a Comment