是否有 Bash 命令将 \r\n 转换为 \n?

use*_*321 20 linux bash carriage-return newlines

是否有 Bash 命令将 \r\n 转换为 \n?

当我将我的脚本从 Windows 上传到 Linux 时,我需要一个像这样的实用程序来使工作正常进行。

小智 6

有一个 Unix 实用程序conv可以转换行尾。它通常使用指向u2dd2uunix2dos或的软链接来调用dos2unix

此外,还有名为fromdosand 的实用程序todos


小智 5

翻译 ( tr ) 在所有 Unix 中可用:

tr -d '\r'  # From \r\n line end (DOS/Windows), the \r will be removed so \n line end (Unix) remains.
Run Code Online (Sandbox Code Playgroud)


小智 5

使用 sed 并找到结尾.txt, .php, .js, .css

 sed -rie 's/\r\n/\n/' \
 $(find . -type f -iregex ".*\.\(txt\|php\|js\|css\)")
Run Code Online (Sandbox Code Playgroud)