sed多行替换问题 [英] Sed multiline replacement question
本文介绍了sed多行替换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了sed替换问题,希望你们中的一个能够为我提供帮助.我确定我缺少一些简单的东西.
I am having a sed replacement issue and am hoping one of you will be able to help me. I am sure I am missing something simple.
所以我有一个包含文本和引号的文件.引号本身可以在一行上,也可以跨多行.我希望报价单本身换行.作为示例,下面是文件
So I have a file containing text and a quote. The quote itself could be on one line or span multiple lines. I want the quote on a new line by itself. As an example here is an example of the file
And he said "This too
shall pass"
我需要将其更改为
And he said
"This too shall pass"
我尝试了以下sed,但无法正常工作-似乎匹配,但是无法换行
I tried the following sed but it didn't work -- it seems to match alright but failed to get a new line
/"This/ {
N
s/"This *\n*too *\n*shall *\n*pass"/\n"This too shall pass"/
}
推荐答案
尝试将\ n替换为\,并使用明确的新行;如下所示
Try replacing the "\n" with \ and an explicit new line; like the following --
/"This/ {
N
s/"This *\n*too *\n*shall *\n*pass"/\
"This too shall pass"/
}
这篇关于sed多行替换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文