我是靠谱客的博主 仁爱马里奥,最近开发中收集的这篇文章主要介绍dos,unix格式文件转换 ,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

转:dos,unix格式文件转换

The UNIX end-of-line character is a line feed/newline character ( /n). The DOS/Windows end-of-line character is a carriage return, followed by a line feed/newline ( /r/n).

Most editors can automatically convert these to the appropriate format, but others, such as Notepad in Windows, cannot.

To convert a UNIX file to DOS using sed(GNU sed3.02.80 or later):
$ sed 's/$//r/' UNIX_file > DOS_file

To convert a DOS file to UNIX file, use trto remove the carriage return:
$ tr -d '/r' < DOS_file > UNIX_file

To accomplish the same thing using  sed:
$ sed 's/^M//' DOS_file > UNIX_file

Note: To generate the ^Mabove, press Ctrl-V, then Ctrl-M.

FTP's ASCIItransfer mode will automatically do the end-of-line conversion between DOS and UNIX systems.

Also, the commands  dos2unixand unix2dosmay be used to perform. the conversion, if present on your system.

  • Emacs

    You can also convert aDOSfile nameddosfile.txtto aUnixtext file usingEmacs, aUnixtext editor. Enter at theUnixshell prompt:
    emacsdosfile.txt
    This will open the file in theEmacstext editor. To remove all the "^M" characters, type
    M-% C-q C-m RET RET !

    It may also be necessary to remove aCtrl-zat the end of the document. To quickly get to the end of the document inEmacs, type
    M->
    If you see aCtrl-zat the end of the document, delete it.

    To convert aUnixfile namedunixfile.txtto aDOStext file, first open it inEmacs. At theUnixshell prompt, enter
    emacsunixfile.txt
    This will open the file in theEmacstext editor. To add carriage returns, which will show up as^MinEmacs, type
    M-% C-q C-j RET C-q C-m C-q C-j RET !
    It may also be necessary to add aCtrl-zat the end of the document. At the very end of the document, press
    C-q C-z

最后

以上就是仁爱马里奥为你收集整理的dos,unix格式文件转换 的全部内容,希望文章能够帮你解决dos,unix格式文件转换 所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(80)

评论列表共有 0 条评论

立即
投稿
返回
顶部