Remove carriage return in Unix

后端 未结 21 2177
傲寒
傲寒 2020-11-22 03:40

What is the simplest way to remove all the carriage returns \\r from a file in Unix?

相关标签:
21条回答
  • 2020-11-22 04:03

    try this to convert dos file into unix file:

    fromdos file

    0 讨论(0)
  • 2020-11-22 04:04

    If you are a Vi user, you may open the file and remove the carriage return with:

    :%s/\r//g
    

    or with

    :1,$ s/^M//
    

    Note that you should type ^M by pressing ctrl-v and then ctrl-m.

    0 讨论(0)
  • 2020-11-22 04:04

    Here is the thing,

    %0d is the carriage return character. To make it compatabile with Unix. We need to use the below command.

    dos2unix fileName.extension fileName.extension

    0 讨论(0)
  • 2020-11-22 04:04

    If you are running an X environment and have a proper editor (visual studio code), then I would follow the reccomendation:

    Visual Studio Code: How to show line endings

    Just go to the bottom right corner of your screen, visual studio code will show you both the file encoding and the end of line convention followed by the file, an just with a simple click you can switch that around.

    Just use visual code as your replacement for notepad++ on a linux environment and you are set to go.

    0 讨论(0)
  • 2020-11-22 04:05

    Once more a solution... Because there's always one more:

    perl -i -pe 's/\r//' filename
    

    It's nice because it's in place and works in every flavor of unix/linux I've worked with.

    0 讨论(0)
  • 2020-11-22 04:06

    you can simply do this :

    $ echo $(cat input) > output
    
    0 讨论(0)
提交回复
热议问题