remove ^M characters from file using sed

前端 未结 9 2286
情书的邮戳
情书的邮戳 2020-12-01 15:35

I have this line inside a file:

ULNET-PA,client_sgcib,broker_keplersecurities
,KEPLER

I try to get rid of that ^M (carriage return) charact

相关标签:
9条回答
  • 2020-12-01 16:31
    alias dos2unix="sed -i -e 's/'\"\$(printf '\015')\"'//g' "
    

    Usage:

    dos2unix file
    
    0 讨论(0)
  • 2020-12-01 16:32

    This is the better way to achieve

    tr -d '\015' < inputfile_name > outputfile_name
    

    Later rename the file to original file name.

    0 讨论(0)
  • 2020-12-01 16:35

    I agree with @twalberg (see accepted answer comments, above), dos2unix on Mac OSX covers this, quoting man dos2unix:

    To run in Mac mode use the command-line option "-c mac" or use the commands "mac2unix" or "unix2mac"

    I settled on 'mac2unix', which got rid of my less-cmd-visible '^M' entries, introduced by an Apple 'Messages' transfer of a bash script between 2 Yosemite (OSX 10.10) Macs!

    I installed 'dos2unix', trivially, on Mac OSX using the popular Homebrew package installer, I highly recommend it and it's companion command, Cask.

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