Friday, October 23, 2009

DOS to UNIX

When you are running a script or compiling a program in a Cygwin Bash Shell, you may encounter the following error:
\r command not found

To handle it, you need to convert this DOS ending character \r at the end of each line to UNIX format.

In Cygwin or UNIX, you can convert an input file (INFILE) in DOS format to an output file (OUTFILE) in Unix format by calling:

> tr -d '\15' < INFILE > OUTFILE
Or you can run this command:
> d2u --safe *
Here --safe mean not touching any binary files. The * is wild card for all files in the current directory. You can type d2u --help in bash for help.

Similarly, you can use u2d to convert UNIX ending line character to DOS format.