unix2dos

From Wikipedia, the free encyclopedia
  (Redirected from Dos2unix)
Jump to: navigation, search

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

[edit] Usage

unix2dos [-p] [file]
-p
Access and modification time of the original file are preserved.
file
File to convert

[edit] Alternatives to unix2dos conversion

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

[edit] See also

[edit] References

  1. ^ A practical guide to Linux. Mark G. Sobell ISBN 0-13-147823-0 Page 55
  2. ^ "tofrodos". http://www.thefreecountry.com/tofrodos/. Retrieved 2009-10-05. 

[edit] External links

  • Tofrodos - software that provides dos2unix and unix2dos
Personal tools
Namespaces
Variants
Actions
Navigation
Interaction
Toolbox
Print/export