替换文字“\r\n"在文本文件中 [英] Replace literal "\r\n" in text file

查看:68
本文介绍了替换文字“\r\n"在文本文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用 <p/> 替换文本文件中的每个 \r\n.

I am trying to replace each \r\n in a text file with <p/>.

我尝试了以下方法但没有成功:

I have tried the following with no luck:

sed 's#\r\n#<p/>#g' test.txt
sed 's#\r\n#<p/>#g' test.txt
sed 's#/\r/\n#<p/>#g' test.txt
sed ':a;N;$!ba;s/\r\n/<p/>/g' test.txt

这是text.txt

https://www.pivotaltracker.com/story/\r\nhttps://www.pivotaltracker.com/story\r\n\r\nSome business text.\r\n\r\nSome business text. Task 123 is still a work in progress but we wanted it in develop to keep everything updated.

推荐答案

所有其他答案都假定您正在尝试处理 Windows 样式的行尾并将它们更改为段落标记.

All of the other answers have assumed that you are trying to handle Windows-style line endings and change them to paragraph tags.

要将字符 \r\n 的文字序列更改为其他内容,只需使用全局替换:

To change the literal sequence of characters \r\n to something else, just use a global substitution:

sed 's!\\r\\n!<p/>!g' file

\ 本身需要转义.

这篇关于替换文字“\r\n"在文本文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆