awk split和concatenate在一行输出中有额外的空间

时间:2016-05-14 16:08:50

标签: awk

以下awk生成current output所有行split。然而,第一行似乎有一个空间,我似乎无法弄清楚为什么。不确定这是否是最佳方式,但它产生的输出接近正确。谢谢你:)。

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

1 个答案:

答案 0 :(得分:2)

你告诉awk在第一个打印语句中打印第一个,的空格。变化

print $1":",$2

print $1":"$2

就像您在第二个打印声明中已有的那样,因此您不会在OFS:之间打印$2值(默认为空格)。