请输入您要查询的百科知识:

 

词条 Unix2dos
释义

  1. Usage

  2. Alternatives to unix2dos conversion

  3. See also

  4. References

  5. External links

{{cleanup HTML|date=February 2019}}{{lowercase}}

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.

[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.

See the manual page of the respective commands.

Alternatives to unix2dos conversion

recode latin1..dos file

Similar results can be achieved with different unix tools to change the trailing newline '\' to a combination of carriage return and newline characters '\\r\', for example with perl or the GNU implementation of sed in-line editing:

perl -i -p -e 's|[\\r\]+|\\r\|g' file

or

sed -i -e 's/\\r*$/\\r/' file

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).

or

perl -i -p -e 's/\\r//g' file

or

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

  • Newline

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
{{unix-stub}}

2 : System administration|Unix text processing utilities

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/11 8:51:15