linux下去掉文件中^M的方法
来源:互联网 发布:nginx conf配置详解 编辑:程序博客网 时间:2024/06/10 16:09
在windows下编辑文件,然后放到linux环境。在windows环境下,换行是表示为\r\n(0x0d0x0a),而在linux下,换行为\n;
在sh脚本对这类文件进行处理时,很容易出现意想不到的情况,比如字符串的比较。
在sh脚本中,个人使用sed -i 's/\r//g' filename的方式,但存在疑问sed -i 's/\r\n/\n/g' filename为什么不生效?
在sh脚本对这类文件进行处理时,很容易出现意想不到的情况,比如字符串的比较。
在sh脚本中,个人使用sed -i 's/\r//g' filename的方式,但存在疑问sed -i 's/\r\n/\n/g' filename为什么不生效?
下述是参考http://hi.baidu.com/qteqpid_pku/item/39568f09905b4bd61ff04680
方法1
#dos2unix filename
ps:有些系统不支持dos2unix命令
方法2
敲出^M字符的方法,ctrl+v然后ctrl+m就可以了。
#sed -i 's/^M//g' filename
或#sed -i 's/\r//g' filename
ps:在应用到脚本时,如果使用第一种,则注意如果脚本被拿到window下编辑再放到linux下的情况
方法3
#vi filename
:%s/^M//g
方法4
#cat filename1 | tr -d "\r" > newfile阅读全文
0 0
- linux下去掉文件中^M的方法
- linux下去掉文件中^M的方法
- linux下去掉文件中^M的方法
- Linux下去掉^M的方法
- Linux下去掉^M的方法
- Linux下去掉^M的方法
- Linux下去掉^M的方法
- Linux下去掉^M的方法
- Linux下去掉^M的方法
- Linux下去掉^M的方法
- Linux下去掉^M的方法
- Linux下去掉^M的方法
- Linux下去掉^M的方法
- Linux下去掉^M的方法
- Linux下去掉^M的方法
- Linux下去掉^M的方法
- Linux下去掉^M的方法
- 去掉文件中^M的方法
- 块模型、内联模型、内联块模型
- sqlite3数据库
- IOS RunLoop浅析 一
- qemu & arm debug uboot kernel
- 程序员业余生活之锻炼身体-中华武术
- linux下去掉文件中^M的方法
- 优化sql语句的策略
- [Docker]5.Docker 容器连接
- 17. Letter Combinations of a Phone Number题解
- IOS 日期的简洁格式展示
- CodeM4
- mybatis知识解惑
- IOS 杂笔-15(知识小点 readonly)
- ANDROID STUDIO系列教程五--GRADLE命令详解与导入第三方包