检测文件

时间:2017-06-16 12:17:59

标签: linux sh

我有一个像这样的日志文件

17-06-14  Name

00:00:02  ABC 1500  0  0  0  
          DEF  0 0  0  0    
          GHI 117  0 0 0 

17-06-14  Name

00:00:07  ABC 1569  0  0  0  
          DEF  0 0  0  0    
          GHI 120  0 0 0  

17-06-14  Name

00:00:12  ABC 1571  0  0  0  
          DEF  3 0  0  0    
          GHI 115  0 0 0  

我喜欢使用linux shell

转换为这样
17-06-14 00:00:02  ABC 1500  0  0  0  
17-06-14 00:00:02  DEF  0 0  0  0    
17-06-14 00:00:02  GHI 117  0 0 0  
17-06-14 00:00:07  ABC 1569  0  0  0  
17-06-14 00:00:07  DEF  0 0  0  0    
17-06-14 00:00:07  GHI 120  0 0 0   
17-06-14 00:00:12  ABC 1571  0  0  0   
17-06-14 00:00:12  DEF  1 0  0  0    
17-06-14 00:00:12  GHI 115  0 0 0 

有人帮我解决了这个问题

1 个答案:

答案 0 :(得分:2)

用awk:

awk '/^$/{next;} /Name/{a=$1;next;}/:/{b=$1;print a,b,$2,$3,$4,$5,$6; next}{print a,b,$1,$2,$3,$4,$5}' file