免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3055 | 回复: 4
打印 上一主题 下一主题

vi中的替换问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-05-23 11:41 |只看该作者 |倒序浏览
请问各位大侠:在windows中写好的文件,上传到solaris后,用vi打开后,发现每一行的后面都加了^M的符号,该如何去掉?谢谢

论坛徽章:
0
2 [报告]
发表于 2006-05-23 11:53 |只看该作者

再问

不用vi可以用命令cat xxx | tr -d \\\\015 > yyy去除,不知道在vi中该如何除掉^M? 谢谢

论坛徽章:
0
3 [报告]
发表于 2006-05-23 12:02 |只看该作者

找到答案了

To remove the ^M characters at the end of all lines in vi, use:

:%s/^V^M//g


The ^v is a CONTROL-V character and ^m is a CONTROL-M. When you type this, it will look like this:

:%s/^M//g


In UNIX, you can escape a control character by preceeding it with a CONTROL-V. The :%s is a basic search and replace command in vi. It tells vi to replace the regular expression between the first and second slashes (^M) with the text between the second and third slashes (nothing in this case). The g at the end directs vi to search and replace globally (all occurrences).

论坛徽章:
0
4 [报告]
发表于 2006-05-23 12:03 |只看该作者
方法一大堆

vi :%s/.$//g

另外^M 可以使用ctrl+v,ctrl+m输入。

论坛徽章:
0
5 [报告]
发表于 2006-05-24 12:09 |只看该作者
用dos2ux  或 dos2unix 转换一下
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP