Unix2dos
This article needs more citations. (November 2020) |
| unix2dos & dos2unix | |
|---|---|
| Original author | John Birchfield |
| Developers | Benjamin Lin, Bernd Johannes Wuebben, Christian Wurll, Erwin Waterlander |
| Release | 1989 |
| Stable release | 7.5.6[1] |
| Operating system | Unix-like, DOS, OS/2, Windows |
| Platform | Cross-platform |
| Type | Command |
| License | FreeBSD style license |
| Website | waterlander |
| Repository | |
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]
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
- recode
$ recode latin1..dos file
- Open the file with Windows Write (WordPad) or Microsoft Word, and save in "plain text" format.
- Similar results can be achieved with different Unix tools to change the trailing newline '\n' to a combination of carriage return and newline characters '\r\n', for example with perl or the GNU implementation of sed in-line editing:
$ perl -i -p -e 's|[\r\n]+|\r\n|g' file$ sed -i -n -z 's/\r*\n/\r\n/g;p' file
Alternatives to dos2unix conversion
For 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' 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 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
See also
References
- ^ "dos2unix / unix2dos - Text file format converters". Retrieved 29 May 2026.
- ^ 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
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.