How to convert Windows end of line in Unix end of line (CR/LF to LF)

后端 未结 8 781
臣服心动
臣服心动 2020-11-29 18:59

I\'m a Java developer and I\'m using Ubuntu to develop. The project was created in Windows with Eclipse and it\'s using the Windows-1252 encoding.

To convert to UTF-8

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 19:41

    sed cannot match \n because the trailing newline is removed before the line is put into the pattern space but can match \r, so you can convert \r\n (dos) to \n (unix) by removing \r

    sed -i 's/\r//g' file
    

    Warning: this will change the original file

    However, you cannot change from unix EOL to dos or old mac (\r) by this. More readings here:

    How can I replace a newline (\n) using sed?

提交回复
热议问题