I'm going to assume you mean carriage returns (CR, "
"
, 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
g o o d b y e
0000017
dos2unix
is the way to go if it's installed on your system:
$ cat infile | dos2unix -U | od -c
0000000 h e l l o
g o o d b y e
0000016
If for some reason dos2unix
is not available to you, then sed
will do it:
$ cat infile | sed 's/
$//' | od -c
0000000 h e l l o
g o o d b y e
0000016
If for some reason sed
is not available to you, then ed
will do it, in a complicated way:
$ echo ',s/
/
/
> w !cat
> Q' | ed infile 2>/dev/null | od -c
0000000 h e l l o
g o o d b y e
0000016
If you don't have any of those tools installed on your box, you've got bigger problems than trying to convert files :-)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…