awk输出重复最后一行,即使只在输入中出现一次

时间:2018-01-17 13:29:49

标签: awk

在下面的awk中,它执行并生成输出中所需的数据行。但是输出No Additional CNV Detected中的最后一行会重复,我不知道为什么它只在输入file1中一次。我将选中的字段从file2添加到file1,但最后一行重复。我需要和END或其他什么。谢谢你:)。

文件1

Controls:
4 expression controls detected
13 NOCALL detected
2178 REF detected
0 ASSAYS_5P_3P absent controls detected
0 ASSAYS_5P_3P NoCall controls detected
No Oncomine Drivers Detected
No Additional Clinvar Detected
No Additional Function Detected
No Additional Fusion Detected
No Additional Hotspots Detected
No Additional CNV Detected

file2的

Total_Targets   Targets_less_than250x   Percent_more_than250x
2353    1   99.9575

AWK

awk '{getline f1 <"file1" ;print f1,$1,$2,$3}' OFS="\t" file2 > out

当前退出

Controls:   Total_Targets   Targets_less_than250x   Percent_more_than250x
4 expression controls detected  2353    1   99.9575
13 NOCALL detected          
2178 REF detected           
0 ASSAYS_5P_3P absent controls detected         
0 ASSAYS_5P_3P NoCall controls detected         
No Oncomine Drivers Detected            
No Additional Clinvar Detected          
No Additional Function Detected         
No Additional Fusion Detected           
No Additional Hotspots Detected         
No Additional CNV Detected          
No Additional CNV Detected          
No Additional CNV Detected          
No Additional CNV Detected

期望

Controls:   Total_Targets   Targets_less_than250x   Percent_more_than250x
4 expression controls detected  2353    1   99.9575
13 NOCALL detected          
2178 REF detected           
0 ASSAYS_5P_3P absent controls detected         
0 ASSAYS_5P_3P NoCall controls detected         
No Oncomine Drivers Detected            
No Additional Clinvar Detected          
No Additional Function Detected         
No Additional Fusion Detected           
No Additional Hotspots Detected         
No Additional CNV Detected

2 个答案:

答案 0 :(得分:3)

使用paste

paste file1 file2 > outputfile

使用pr

pr -mtJ file1 file2 > outputfile
  

测试结果:

输入文件:

$ cat f1
Controls:
4 expression controls detected
13 NOCALL detected
2178 REF detected
0 ASSAYS_5P_3P absent controls detected
0 ASSAYS_5P_3P NoCall controls detected
No Oncomine Drivers Detected
No Additional Clinvar Detected
No Additional Function Detected
No Additional Fusion Detected
No Additional Hotspots Detected
No Additional CNV Detected

$ cat f2
Total_Targets   Targets_less_than250x   Percent_more_than250x
2353    1   99.9575

paste命令的输出:

$ paste f1 f2
Controls:   Total_Targets   Targets_less_than250x   Percent_more_than250x
4 expression controls detected  2353    1   99.9575
13 NOCALL detected  
2178 REF detected   
0 ASSAYS_5P_3P absent controls detected 
0 ASSAYS_5P_3P NoCall controls detected 
No Oncomine Drivers Detected    
No Additional Clinvar Detected  
No Additional Function Detected 
No Additional Fusion Detected   
No Additional Hotspots Detected 
No Additional CNV Detected  

pr命令的输出:

$ pr -mtJ f1 f2
Controls:   Total_Targets     Targets_less_than250x   Percent_more_than250x
4 expression controls detected  2353    1   99.9575
13 NOCALL detected  
2178 REF detected   
0 ASSAYS_5P_3P absent controls detected 
0 ASSAYS_5P_3P NoCall controls detected 
No Oncomine Drivers Detected    
No Additional Clinvar Detected  
No Additional Function Detected 
No Additional Fusion Detected   
No Additional Hotspots Detected 
No Additional CNV Detected  

答案 1 :(得分:1)

关注awk可能对您有帮助。

awk 'FNR==NR{a[FNR]=$0;next} {print $0,a[FNR]}'  Input_file2   Input_file1

您可以通过在命令的最后一步执行> outfile将其输出到输出文件。