我的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
有时链接包含新行,我想删除它们。 我怎样才能从最终输出变为新线:
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
我看到this question,我尝试了类似的东西
sed -n '$!{ 1{x;d}; H}; ${ H;x;s|\n\([^1-9]d{10}\)| \1|g;p}'
但它不起作用
我会非常感谢你的帮助,因为我遇到了这个问题
答案 0 :(得分:1)
这里是awk-oneliner:
awk '{printf "%s%s", (NR>1&&/^[0-9]{10}/?"\n":""),$0}END{print ""}' file
看到这个测试:
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
答案 1 :(得分:0)
你可以试试下面的perl oneliner命令,
perl -0777pe 's/\n(?!\d{10},|$)//g' file
示例:强>
$ cat file
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
$ perl -0777pe 's/\n(?!\d{10},|$)//g' file
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