shell crlf to lf


UNIX/Linux Commands

You can use the following tools:

  • dos2unix (also known as fromdos) – converts text files from the DOS format to the Unix
    format
  • unix2dos (also known as todos) – converts text files from the Unix format to the DOS format.
  • sed – You can use sed command for same purpose
  • tr command
  • Perl one liner

Task: Convert DOS file to UNIX format

Type the following command to convert file called myfile.txt:
$ dos2unix myfile.txt

However above command will not make a backup of original file myfile.txt. To make a backup of original file. The original file is renamed with the original filename and a .bak extension. Type the following command:
$ dos2unix -b myfile.txt

Task: Convert UNIX file to DOS format

Type the following command to convert file called myfile.txt:
$ unix2dos myfile.txt
$ unix2dos -b myfile.txt

Task: Convert Dos TO Unix Usingtr Command

Type the following command:

tr -d '\r' < input.file > output.file

Task: Convert Dos TO Unix UsingPerl One Liner

Type the following command:

perl -pi -e 's/\r\n/\n/g' input.file

Task: Convert UNIX to DOS format usingsed command

Type the following command if you are using bash shell:
$ sed 's/$'"/`echo \\\r`/" input.txt > output.txt
Note: sed version may not work under different UNIX/Linux variant,refer your local sed man page for more info.

Task: Convert DOS newlines (CR/LF) to Unix format usingsed command

If you are using BASH shell type the following command (press Ctrl-V then Ctrl-M to get pattern or special symbol)
$ sed 's/^M$//' input.txt > output.txt
Note: sed version may not work under different UNIX/Linux variant, refer your local sed man page for more info.

优质内容筛选与推荐>>
1、css3动态边框
2、Improve Score Better With AWS-Solution-Architect-Associate Exam Cram
3、程序员:各种快捷键的用法及掌握 .
4、基于node.js 的 websocket的移动端H5直播开发
5、《算法导论》学习总结 — 2.第一章 && 第二章 && 第三章


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号





    联系我们

    欢迎来到TinyMind。

    关于TinyMind的内容或商务合作、网站建议,举报不良信息等均可联系我们。

    TinyMind客服邮箱:support@tinymind.net.cn