Remove carriage return in Unix

后端 未结 21 2173
傲寒
傲寒 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:09

    sed -i s/\r// or somesuch; see man sed or the wealth of information available on the web regarding use of sed.

    One thing to point out is the precise meaning of "carriage return" in the above; if you truly mean the single control character "carriage return", then the pattern above is correct. If you meant, more generally, CRLF (carriage return and a line feed, which is how line feeds are implemented under Windows), then you probably want to replace \r\n instead. Bare line feeds (newline) in Linux/Unix are \n.

提交回复
热议问题