因为windows下文本的换行符为rn,而unix下只为n,因此windows换行符(rn)与unix换行符(n)互转,最直观的做法是直接用sed替换。
windows换行符转unix换行符:
sed -i -e 's/rn/n/g' test.txt
unix换行符转windows换行符:
sed -i -e 's/n/rn/g' test.txt
或者使用删除r字符的思路,将windows换行符转换成unix换行符
sed -i 's/^M//g' test.txt
上面命令中,符号^M即为 r ,即把r都删除掉
或者更直观点的做法为:
sed -i -e 's/r//g' test.txt
linux下想要查看文件的换行符,其中一种方法可以使用cat -A filename 命令:
[root@localhost ~]# cat -A test.txt
this is a new line test^M$
this is a new line test1^M$
r对应符号^M,n对应符号$.



