![](/img/trans.png)
[英]How do I remove first 5 characters in each line in a text file using vi?
[英]How to remove ^M characters in the middle of each line in vi editor
我正在尝试从文件中每行的中间删除控制字符。 这是我的以下数据。 我使用了以下命令,但它似乎不起作用。
Command:
:%s/^M//g
Data:
53,v42,p11,51097,310780,ok^M,fraud
56,v45,p11,260,1925,ok^M,fraud
68,v42,p11,51282,278770,ok^M,fraud
96,v49,p14,212,1545,ok^M,fraud
163,v50,p20,373819,1006375,ok^M,fraud
204,v50,p26,36917,117195,ok^M,fraud
241,v70,p33,21777,91360,ok^M,fraud
Output Warning:
E486: Pattern not found: ^M
看一下这篇文章: http : //www.tech-recipes.com/rx/150/remove-m-characters-at-end-of-lines-in-vi/
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
基本理由是,键入^ M会搜索文字解释,即^和M两个字符,而您想从输入中构造实际的控制字符。
是的,您按住“ Ctrl”和键“ v”,然后按住“ Ctrl”和键“ m”,而不是按字面意思输入“ ^ v”和“ ^ m”。
如何使用VI编辑器从UNIX文件中删除^ M,请使用此命令。
:%S(CTRL + V)(按Ctrl + M)/
重要!! –按(Ctrl-v)(Ctrl-m)组合键输入^ M字符,请勿使用“ ^”和M。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.