两个词之间删除换行符 [英] Remove newlines between two words
本文介绍了两个词之间删除换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个看起来像一个文件:
I have a file that looks like:
name: charles
key1: how
are
you?
name: erika
key2: I'm
fine,
thanks
name: ...
我怎么能删除新行说,关键\\ D +和名的?它应该是这样的:
How could I remove the new lines that between "key\d+" and "name:"? It should look like this:
name: charles
key1: how are you?
name: erika
key2: I'm fine, thanks
name: ...
我试图用sed或awk的,但没有成功。有没有什么办法,以清洁工作线?
I'm trying to use sed or awk but without any success. Is there any way to clean that lines?
有什么办法去除之间的换行符键\\ D +和\\ W +:
Is there any way to remove the newlines between "key\d+:" and "\w+:"?
推荐答案
这样的事?
kent$ awk '/^key.:/{p=1}/^name:/{p=0}
{if(p)printf "%s",$0;else printf "%s%s\n", (NR==1?"":RS),$0}' file
name: charles
key1: howareyou?
name: erika
key2: I'mfine,thanks
name: ...
处理空间:
awk '/^key.:/{p=1}/^name:/{p=0}
{if(p)printf "%s%s",(/^key.:/?"":" "),$0;
else printf "%s%s\n", (NR==1?"":RS),$0}' file
输出:
name: charles
key1: how are you?
name: erika
key2: I'm fine, thanks
name: ...
这篇关于两个词之间删除换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文