In the article we present today we want to address the topic of Unix2dos from a broad and varied perspective. Unix2dos is a topic that has generated great interest and debate over the years, covering different aspects and triggering multiple reflections. In this sense, we propose to analyze in depth the various aspects that Unix2dos presents, as well as its implications in today's society. To do this, we will examine different approaches and opinions of experts on the subject, in order to offer a complete and truthful vision of this very relevant topic. Through an exhaustive analysis, we aim to provide our readers with a broad and updated vision of Unix2dos, with the aim of promoting critical and enriching reflection.
This article needs additional citations for verification. (November 2020) |
| unix2dos & dos2unix | |
|---|---|
| Original author | John Birchfield |
| Developers | Benjamin Lin, Bernd Johannes Wuebben, Christian Wurll, Erwin Waterlander |
| Initial release | 1989 |
| Stable release | 7.5.2[1] |
| Repository | |
| Operating system | Unix-like, DOS, OS/2, Windows |
| Platform | Cross-platform |
| Type | Command |
| License | FreeBSD style license |
| Website | waterlan |
unix2dos (sometimes named todos or u2d) 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 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.[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'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.
$ recode latin1..dos file
$ perl -i -p -e 's|+|\r\n|g' file$ sed -i -n -z 's/\r*\n/\r\n/g;p' fileFor the opposite conversion (dos2unix) it is possible to use, for example, the utility tr 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' fileNote: 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 col 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 -b option tells col not to output backspace characters.
$ col -b < InFile > OutFile