remove windows under linux file \ r

Unix system, the end of each line only "<wrapping>", that is, "\ n";
inside Windows system, the end of each line is "<line feed> <Enter>", namely "\ n \ r".
A direct result, the Unix file system is opened in Windows, then all the text will become a line;
and Windows, the file is opened, then under Unix, at the end of each line might be more of a symbol ^ M.

method 1:

在命令模式下:输入:%s/^M//g 然后,回车即可替换
注,其中”^M”的输入,分别是“Ctrl+v”、“Ctrl+M”键生成的

Method 2:

使用vi打开文本文件
vi dos.txt
命令模式下输入
:set fileformat=unix
:w

Method 3:

使用sed 工具
sed ’s/^M//’ filename > tmp_filename

Method 4:

既然window下的回车符多了‘\r’,那么当然通过删除‘\r’ ,也可以实现:
tr -d ‘\r’

The method most commonly used method :()

在终端下敲命令:
$ dos2unix filename
直接转换成unix格式,就OK了!~

sed -i 's/\r//' startup.sh

window下默认是 \r\n
linux下是\n
unix下是\r

Guess you like

Origin blog.51cto.com/14013608/2443455