除去新行如果下一行没有与前pression开始 [英] remove new line if next line does not begin with an expression
本文介绍了除去新行如果下一行没有与前pression开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的CSV文件列像
start_time,end_time,link
1407233497,1407233514,http://s.youtube.com/stream_204?event=streamingstats&fmt=n
1407233498,1407233515,http://s.youtube.com/stream_204?event=cenjreaecnjcd
mingstats&fmt=n
1407233499,1407233516,http://s.youtube.com/stream_204?event=weedwcecd
有时候链接包含新的生产线,我想删除它们。
我怎么能做到这一点从这样最后输出的新行变为:
Some times link contains new lines and I want to remove them. How can I do that the new line from the so the final output becomes:
1407233497,1407233514,http://s.youtube.com/stream_204?event=streamingstats&fmt=n
1407233498,1407233515,http://s.youtube.com/stream_204?event=cenjreaecnjcdmingstats&fmt=n
1407233499,1407233516,http://s.youtube.com/stream_204?event=weedwcecd
我看了<一个href=\"http://stackoverflow.com/questions/6588113/remove-new-line-if-next-line-does-not-begin-with-a-number\">this问题,我尝试类似的东西。
sed -n '$!{ 1{x;d}; H}; ${ H;x;s|\n\([^1-9]d{10}\)| \1|g;p}'
,但它不工作
我会很帮忙AP preciate,因为我卡住了这个问题。
I would be really appreciate for help, because I got stuck with this problem
推荐答案
下面是AWK-oneliner:
here is awk-oneliner:
awk '{printf "%s%s", (NR>1&&/^[0-9]{10}/?"\n":""),$0}END{print ""}' file
看到这样的测试:
see this test:
kent$ cat f
1407233497,1407233514,http://s.youtube.com/stream_204?event=streamin
gstats&fmt=n
1407233498,1407233515,http://s.youtube.com/stream_204?event=cenjreaecnjcd
mi
ngstats&fmt=n
1407233499,140723
3516,http://s.yout
ube.com/stream_204?event=weedwcecd
kent$ awk '{printf "%s%s", (NR>1&&/^[0-9]{10}/?"\n":""),$0}END{print ""}' f
1407233497,1407233514,http://s.youtube.com/stream_204?event=streamingstats&fmt=n
1407233498,1407233515,http://s.youtube.com/stream_204?event=cenjreaecnjcdmingstats&fmt=n
1407233499,1407233516,http://s.youtube.com/stream_204?event=weedwcecd
这篇关于除去新行如果下一行没有与前pression开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文