unix2dos

From English Wikipedia @ Freddythechick
(Redirected from Dos2unix)
unix2dos & dos2unix
Original author(s)John Birchfield
Developer(s)Benjamin Lin, Bernd Johannes Wuebben, Christian Wurll, Erwin Waterlander
Initial release1989; 36 years ago (1989)
Operating systemUnix-like, DOS, OS/2, Windows
PlatformCross-platform
TypeCommand
LicenseFreeBSD style license
Websitewaterlan.home.xs4all.nl/dos2unix.html

<syntaxhighlight lang="text" class="" style="" inline="1">unix2dos</syntaxhighlight> (sometimes named <syntaxhighlight lang="text" class="" style="" inline="1">todos</syntaxhighlight> or <syntaxhighlight lang="text" class="" style="" inline="1">u2d</syntaxhighlight>) is a tool to convert line breaks in a text file from Unix format (Line feed) to DOS format (carriage return + Line feed) and vice versa. When invoked as <syntaxhighlight lang="text" class="" style="" inline="1">unix2dos</syntaxhighlight> the program will convert a Unix text file to DOS format, when invoked as <syntaxhighlight lang="text" class="" style="" inline="1">dos2unix</syntaxhighlight> it will convert a DOS text file to Unix format. [1]

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, fromdos/todos, 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

  • Open the file with Windows Write (WordPad) or Microsoft Word, and save in "plain text" format.
  • [\r\n]+
  • \r\n

Alternatives to dos2unix conversion

For the opposite conversion (dos2unix) it is possible to use, for example, the utility tr with the <syntaxhighlight lang="text" class="" style="" inline="1">-d '\r'</syntaxhighlight> flag to remove the carriage return characters:

  • <syntaxhighlight lang="console" inline>

$ tr -d '\r' < file > file2 # For ASCII and other files which do not contain multibyte characters (Not utf-8 safe). </syntaxhighlight>

  • <syntaxhighlight lang="console" inline>

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

  • <syntaxhighlight lang="console" inline>

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

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 the <syntaxhighlight lang="text" class="" style="" inline="1">col</syntaxhighlight> 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 (^M) line endings. After execution, OutFile is either created or replaced, and contains UNIX line endings. The <syntaxhighlight lang="text" class="" style="" inline="1">-b</syntaxhighlight> option tells <syntaxhighlight lang="text" class="" style="" inline="1">col</syntaxhighlight> not to output backspace characters. <syntaxhighlight lang="console"> $ col -b < InFile > OutFile </syntaxhighlight>

See also

References

  1. ^ A practical guide to Linux. Mark G. Sobell ISBN 0-13-147823-0 Page 55

External links

  • Tofrodos - software that provides dos2unix and unix2dos
  • Dos2Unix - Dos2Unix / Unix2Dos - Text file format converters