remove CR line terminators

后端 未结 3 1744
不思量自难忘°
不思量自难忘° 2021-01-12 14:54

Firstly I would say that I have read this post however I still have problems for the CR line terminators.

There is a file called build_test.sh

相关标签:
3条回答
  • 2021-01-12 15:25

    Also, if you work with vim, you can enforce UNIX line endings by executing

    :set fileformat=unix
    :w
    

    or just add

    set fileformat=unix
    

    to your .vimrc file

    0 讨论(0)
  • 2021-01-12 15:35

    I finally figured out that I could use this command:

    tr '^M' '\n' <build_test.sh >build_test_nocr.sh
    

    where ^M is added by pressing Ctrl+v and Enter keys.Alternately, this has the same effect:

    tr '\r' '\n' <build_test.sh >build_test_nocr.sh
    
    0 讨论(0)
  • 2021-01-12 15:37

    Simple \r terminators for newlines are "old Mac" line terminators, it is strange that an editor in 2012+ even generates files with such line terminators... Anyway, you can use the mac2unix command, which is part of the dos2unix distribution:

    # Edits thefile inline
    mac2unix thefile
    # Takes origfile as an input, outputs to dstfile
    mac2unix -n origfile dstfile
    

    This command will not munge files which have already expected line terminators, which is a bonus. And the reverse (unix2mac) also exists.

    Note that mac2unix is the same as dos2unix -c mac.

    0 讨论(0)
提交回复
热议问题