This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Unix2dos" – news ·newspapers ·books ·scholar ·JSTOR(November 2020) (Learn how and when to remove this message) |
Original author(s) | John Birchfield |
---|---|
Developer(s) | Benjamin Lin, Bernd Johannes Wuebben, Christian Wurll, Erwin Waterlander |
Initial release | 1989; 36 years ago (1989) |
Stable release | |
Repository | |
Operating system | Unix-like,DOS,OS/2,Windows |
Platform | Cross-platform |
Type | Command |
License | FreeBSD style license |
Website | waterlan |
unix2dos
(sometimes namedtodos
oru2d
) is a tool to convertline breaks in atext file fromUnix format (Line feed) toDOS format (carriage return + Line feed) and vice versa. When invoked asunix2dos
the program will convert a Unix text file to DOS format, when invoked asdos2unix
it will convert a DOS text file to Unix format.[2]
Unix2dos and dos2unix are not part of the Unix standard. Commercial Unixes usually come with their own implementation of unix2dos/dos2unix, like SunOS/Solaris'sdos2unix/unix2dos, HP-UX'sdos2ux/ux2dos and Irix'sto_unix/to_dos.
There exist many open source alternatives with different command names and options likedos2unix/unix2dos,d2u/u2d,fromdos/todos,endlines,flip. The multi-call binarybusybox includes an implementation ofunix2dos/dos2unix.
See themanual page of the respective commands.
$recodelatin1..dosfile
$perl-i-p-e's|[\r\n]+|\r\n|g'file
$sed-i-n-z's/\r*\n/\r\n/g;p'file
For the opposite conversion (dos2unix) it is possible to use, for example, the utilitytr with the-d '\r'
flag to remove the carriage return characters:
$tr-d'\r'<file>file2# For ASCII and other files which do not contain multibyte characters (Not utf-8 safe).
$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 (\r) present in the input will be removed.
An alternative to the dos2unix conversion is possible by using thecol
command that is available onLinux and other Unix-like operating systems, including Mac OS X. In the following case, InFile contains the undesired DOS (^M) line endings. After execution, OutFile is either created or replaced, and contains UNIX line endings. The-b
option tellscol
not to output backspace characters.
$col-b<InFile>OutFile