unix2dos (sometimes named todos or u2d) is a Unix tool to convert an ASCII text file from Unix format (line break) to DOS format (carriage return and line break) and vice versa. When invoked as unix2dos the program will convert a Unix text file to DOS format, when invoked as dos2unix it will convert a DOS text file to UNIX format. [1]
The tofrodos package provides this functionality to Linux, Mac OSX, and can be downloaded for Windows.[2]
Contents |
unix2dos [-p] [file]
Similar results can be achieved with different unix tools to change the trailing newline '\n' to combination of carriage return and newline characters '\r\n' for example with the sed or perl in-line editing:
perl -i -p -e 's/\n/\r\n/' file sed -i -e 's/$/\r/' file
For opposite conversion (dos2unix) it is possible to alternatively use for example the utility tr to change a text file from Windows or OS X into a Linux text file by using the -d '\r' flag to remove carriage return characterss:
tr -d '\r' < file > file2 perl -i -p -e 's/\r//' file sed -i -e 's/\r//' file