2016-05-14 73 views
0

以下awk會生成current output,其中所有行split。然而,第一行似乎有一個空間,我似乎無法弄清楚爲什麼。不知道這是否是最好的方法,但它會產生接近正確的輸出。謝謝 :)。awk拆分和連接在輸出的一行中有額外空間

AWK

awk '{split($6,a,":"); print $1":",$2,$3,a[1],a[2],a[6],a[7]} {split($7,a,":"); print $1":"$2,$3,a[1],a[2],a[6],a[7]} {split($8,a,":"); print $1":"$2,$3,a[1],a[2],a[6],a[7]} {split($9,a,":"); print $1":"$2,$3,a[1],a[2],a[6],a[7]} {split($10,a,":"); print $1":"$2,$3,a[1],a[2],a[6],a[7]}' input > parse 

輸入文件(分隔標籤)

chr1 13408 C 1 =:0:0.00:0.00:0.00:0:0:0.00:0.00:0.00:0:0.00:0.00:0.00 A:0:0.00:0.00:0.00:0:0:0.00:0.00:0.00:0:0.00:0.00:0.00 C:1:2.00:28.00:2.00:0:1:0.00:0.02:0.00:0:0.00:0.00:0.00 G:0:0.00:0.00:0.00:0:0:0.00:0.00:0.00:0:0.00:0.00:0.00 T:0:0.00:0.00:0.00:0:0:0.00:0.00:0.00:0:0.00:0.00:0.00 N:0:0.00:0.00:0.00:0:0:0.00:0.00:0.00:0:0.00:0.00:0.00 

電流輸出(解析)

chr1: 13408 C A 0 0 0 (has a space between `chr1:` and `13408`) 
chr1:13408 C C 1 0 1 
chr1:13408 C G 0 0 0 
chr1:13408 C T 0 0 0 
chr1:13408 C N 0 0 0 

所需的輸出

chr1:13408 C A 0 0 0 (has no space between `chr1:` and `13408`) 
chr1:13408 C C 1 0 1 
chr1:13408 C G 0 0 0 
chr1:13408 C T 0 0 0 
chr1:13408 C N 0 0 0 
+0

謝謝,我甚至沒有注意到......謝謝:)。 – Chris

回答

2

特殊照顧告訴AWK你的第一個print語句來打印與第一,的空間。更改

print $1":",$2 

print $1":"$2 

像你已經在你的第二個print語句,所以你沒有得到OFS值(默認爲空格):$2之間打印。