Unix2dos


is a tool to convert line breaks in a text file from Unix format to DOS format and vice versa. When invoked as the program will convert a Unix text file to DOS format, when invoked as it will convert a DOS text file to Unix format.

Usage

Unix2dos and dos2unix are not part of the Unix standard. Commercial Unixes usually come with their own implementation of unix2dos/dos2unix, like SunOS/Solaris's dos2unix/unix2dos, HP-UX's dos2ux/ux2dos and Irix's to_unix/to_dos.
There exist many open source alternatives with different command names and options like dos2unix/unix2dos, d2u/u2d, , endlines, flip. The multi-call binary busybox includes an implementation of unix2dos/dos2unix.
See the manual page of the respective commands.

Alternatives to unix2dos conversion

Alternatives to dos2unix conversion

For the opposite conversion it is possible to use, for example, the utility tr with the flag to remove the carriage return characters:
$ tr -d '\r' < file > file2 # For ASCII and other files which do not contain multibyte characters.

$ perl -i -p -e 's/\r//g' file

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

Note: The above method assumes there are only DOS line breaks in the input file. Any Mac line breaks present in the input will be removed.
An alternative to the dos2unix conversion is possible by using the command that is available on Linux and other Unix-like operating systems, including Mac OS X. In the following case, InFile contains the undesired DOS line endings. After execution, OutFile is either created or replaced, and contains UNIX line endings. The option tells not to output backspace characters.

$ col -b < InFile > OutFile