以下awk
在inheritance
中插入$10
,并将每行中的值默认为.
问题是它似乎拆分了旧$10
进入两个单独的字段导致数据移位。
例如,$10
在awk
被nonsynonymous SNV
之后被分成两列,我不知道为什么或如何修复它。
文件
R_Index Chr Start End Ref Alt Func.IDP.refGene Gene.IDP.refGene GeneDetail.IDP.refGene ExonicFunc.IDP.refGene AAChange.IDP.refGene
1 chr1 949608 949608 G A exonic ISG15 . nonsynonymous SNV ISG15:NM_005101.3:exon2:c.248G>A:p.S83N
22 chr1 1650845 1650845 G A intergenic DVL1,GABRD dist=366353;dist=299923 . .
23 chr1 1957037 1957037 T C exonic GABRD . synonymous SNV GABRD:NM_000815.4:exon4:c.330T>C:p.G110G
当前输出
R_Index Chr Start End Ref Alt Func.IDP.refGene Gene.IDP.refGene GeneDetail.IDP.refGene Inheritence ExonicFunc.IDP.refGene AAChange.IDP.refGene
1 chr1 949608 949608 G A exonic ISG15 . . nonsynonymous SNV ISG15:NM_005101.3:exon2:c.248G>A:p.S83N
22 chr1 1650845 1650845 G A intergenic DVL1,GABRD dist=366353;dist=299923 . . .
23 chr1 1957037 1957037 T C exonic GABRD . . synonymous SNV GABRD:NM_000815.4:exon4:c.330T>C:p.G110G
AWK
awk '{$10=NR==1?"Inheritence" OFS $10:"." OFS $10} 1' OFS="\t" file > output
修改awk
print
awk '{print $11}' output
ExonicFunc.IDP.refGene
nonsynonymous
.
synonymous
awk '{print $12}' output
AAChange.IDP.refGene
SNV
.
SNV
答案 0 :(得分:2)
使用GNU sed
sed -r -e '1 s/^(\S+\s+){9}/\0Inheritence\t/' -e '2,$ s/^(\S+\s+){9}/\0.\t/' file > output
\0
包含整个匹配的文字
修改:可以简化为
sed -E '1s/[^ \t]+/Inheritence\t&/10; 2,$s//.\t&/10'
[^ \t]+
,而不是空格/制表符10
替换第10次出现[^ \t]+
作为空匹配部分GNU sed
以外的版本