(ZT)Eliminate ^M character using vi(Linux)

编程入门 行业动态 更新时间:2024-10-26 00:24:02

Eliminate ^M character using vi(Linux)

Sometimes certain characters(for eg.,^M characters)are placed in a file during a DOS to UNIX conversion.To modify these files with a lot of ^M symbol at the end of every line,using the vi editor,use the following command:
(To get the ^M hold the control key, press V then M (Both while holding the control key) and the ^M will appear.)
This command will find all occurances and replace them with nothing. Here,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). Remove ^M characters at end of lines in vi 有一点需要注意的是,如果采用命令vi file_name将无法看到这些非法字符,也无法执行上面的替换操作,必须以binary方式打开: vi file_name -b

转载于:https://blog.51cto/land611/111325

更多推荐

(ZT)Eliminate ^M character using vi(Linux)

本文发布于:2023-06-13 09:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1372267.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:character   Eliminate   Linux   vi

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!