将与模式匹配的行移至上一行 [英] move line which matches pattern to previous line
本文介绍了将与模式匹配的行移至上一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个结构为
12312
desc: bleh...
9938
desc: blah...
desc: bloh...
desc: blih...
desc: bluh...
9912
desc: blah...
我想将匹配模式"desc:"的行移至上一行,或删除每个模式"desc:"之前的行中的"\ n".
and i want to move line which matches pattern "desc:" to previous line or delete '\n' in line which goes before every pattern "desc:".
所需的输出:
12312 desc: bleh...
9938 desc: blah... desc: bloh... desc: blih... desc: bluh...
9912 desc: blah...
我尝试过
awk '!/desc:/{
printf "%s ",$0
getline
printf "%s \n",$0
}
/desc/{print}' file
没有结果.
实际上所有数据都是 awk -F \'{print $ 4" \ t"$ 6}'的输出
也许我首先可以做点什么?
actually all the data is the output of awk -F\" '{print $4 "\t" $6}'
maybe i can do something in the first place?
推荐答案
sed
oneliner
sed
oneliner
sed ':a $!N;s/\ndesc/ desc/;ta P;D'
将输出
12312 desc: bleh...
9938 desc: blah... desc: bloh... desc: blih... desc: bluh...
9912 desc: blah...
这篇关于将与模式匹配的行移至上一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文