I'm going to assume you mean carriage returns (CR, "\r"
, 0x0d
) at the ends of lines rather than just blindly within a file (you may have them in the middle of strings for all I know). Using this test file with a CR at the end of the first line only:
$ cat infile
hello
goodbye
$ cat infile | od -c
0000000 h e l l o \r \n g o o d b y e \n
0000017
dos2unix
如果您的系统上安装了它,则可以这样:
$ cat infile | dos2unix | od -c
0000000 h e l l o \n g o o d b y e \n
0000016
如果由于某种原因dos2unix
那么您无法使用sed
会做的:
$ cat infile | sed 's/\r$//' | od -c
0000000 h e l l o \n g o o d b y e \n
0000016
如果由于某种原因sed
那么您无法使用ed
将以一种复杂的方式做到这一点:
$ echo ',s/\r\n/\n/
> w !cat
> Q' | ed infile 2>/dev/null | od -c
0000000 h e l l o \n g o o d b y e \n
0000016
如果你没有any在您的盒子上安装的这些工具中,您遇到的问题比尝试转换文件更大:-)