sed:根据第二行加入行 [英] sed: joining lines depending on the second one
本文介绍了sed:根据第二行加入行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件,偶尔会有分割线.行以+"开头(可能前面有空格)表示拆分.
I have a file that, occasionally, has split lines. The split is signaled by the fact that the line starts with '+' (possibly preceeded by spaces).
line 1
line 2
+ continue 2
line 3
...
我想加入分割线:
line 1
line 2 continue 2
line 3
...
使用sed.我不清楚如何将一行与 前面的 连接起来.
using sed. I'm not clear how to join a line with the preceeding one.
有什么建议吗?
推荐答案
这可能对你有用:
sed 'N;s/\n\s*+//;P;D' file
<小时>
这实际上是四个命令:
These are actually four commands:
N
将输入文件中的行追加到模式空间s/\n\s*+//
删除换行符,跟在空格和加号之后P
从模式空间打印行直到第一个换行符D
从模式空间中删除行直到第一个换行符,例如刚刚打印出来的部分
相关的手册页部分是
这篇关于sed:根据第二行加入行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文