Windows文件格式的换行符和Linux文件的换行符在linux系统下的转换方法

■Windows文件格式的换行符和Linux文件的换行符的区别
换行符dao:
1.windows中的换行符是\r\n,对应的ASCII码值(回车符:\r=0x0d (13) return,换行符\n=0x0a (10) newline)

  1. linux/unix下的换行符是\n,对应的ASCII码值(换行符:\n=0x0a (10) newline)

■Windows文件格式的换行符和Linux文件的换行符在linux下的转换方法:
1.unix2dos和dos2unix命令
unix2dos:Linux文件格式的换行符转化为Windows文件格式的换行符
dos2unix:Windows文件格式的换行符转化Linux文件格式的换行符

2.sed命令
sed -i 's/\r//' filename > newfilename # Windows文件格式的换行符转化Linux文件格式的换行符
sed -i 's/\n/\r\n/' filename > newfilename # Linux文件格式的换行符转化为Windows文件格式的换行符

3.Vim编辑器
命令模式输入:set fileformat=unix Windows文件格式的换行符转化Linux文件格式的换行符 保存即可
命令模式输入:set fileformat=dos Linux文件格式的换行符转化为Windows文件格式的换行符 保存即可

猜你喜欢

转载自blog.51cto.com/14801055/2550918
今日推荐