简体   繁体   English

正则表达式用\\ n替换^ M或删除^ M

[英]regular expression to replace ^M with \n or to remove ^M

I have a file where I want to remove ^M character from below 我有一个文件要从下面删除^ M字符

line1;^Mline2; 第1行; ^ Mline2;

to have output as below: 具有以下输出:

line1; 一号线; line2; 2号线;

How can I achieve this without creating a temporary file? 在不创建临时文件的情况下如何实现? Would appreciate any shell command, perl command or eclipse find and replace. 将不胜感激任何shell命令,perl命令或Eclipse查找和替换。

I'm not sure if by ^M you mean the literal string ^M or the control-character (carriage-return). 我不确定^M是否表示文字字符串^M或控制字符(回车)。 If you mean the literal string: 如果您的意思是文字字符串:

sed -e 's/\^M/\n/g' file

If you mean carriage-return: 如果您的意思是回车:

sed -e 's/\r/\n/g' file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM