awk向字段中的每个图案添加文本
在下面的awk向字段中的每个图案添加文本,awk,Awk,在下面的awk中,我试图将:p.=添加到每个$7中,前提是其中包含模式/NM/。如果$7中只有一个NM,如第2行,则下面的代码似乎就是这样。但是,如果在$7中有多个NM,如第3行,则:p.=仅添加到最后一行。A用于分离字段中的多个NM。我添加了评论,但不确定我没有做什么,这是必要的。谢谢:) 输入制表符分隔 R_Index Chr Start End Ref Alt Detail.refGene Gene.refGene 1 chr1 948846 948846 - A
awk
中,我试图将:p.=
添加到每个$7
中,前提是其中包含模式/NM/
。如果$7
中只有一个NM
,如第2行,则下面的代码似乎就是这样。但是,如果在$7
中有多个NM
,如第3行,则:p.=
仅添加到最后一行。A
用于分离字段中的多个NM
。我添加了评论,但不确定我没有做什么,这是必要的。谢谢:)
输入制表符分隔
R_Index Chr Start End Ref Alt Detail.refGene Gene.refGene
1 chr1 948846 948846 - A dist=1 ISG15
2 chr1 948870 948870 C G NM_005101:c.-84C>G ISG15
3 chr1 948921 948921 T C NM_005101:c.-33T>C;NM_005101:c.-84C>G ISG15
4 chr1 949654 949654 A G . ISG15
R_Index Chr Start End Ref Alt Detail.refGene Gene.refGene
1 chr1 948846 948846 - A dist=1 ISG15
2 chr1 948870 948870 C G NM_005101:c.-84C>G:p.= ISG15
3 chr1 948921 948921 T C NM_005101:c.-33T>C;NM_005101:c.-84C>G:p.=p.= ISG15
4 chr1 949654 949654 A G . ISG15
R_Index Chr Start End Ref Alt Detail.refGene Gene.refGene
1 chr1 948846 948846 - A dist=1 ISG15
2 chr1 948870 948870 C G NM_005101:c.-84C>G:p.= ISG15
3 chr1 948921 948921 T C NM_005101:c.-33T>C:p.=;NM_005101:c.-84C>G:p.= ISG15
4 chr1 949654 949654 A G . ISG15
awk
awk '
BEGIN { FS=OFS="\t" } # define FS and OFS as tab and start processing
$7 ~ /NM/ { # look for pattern NM in $7
# split $7 by ";" and cycle through them
i=split($7,NM,";")
for (n=1; n<=i; n++) {
sub("$", ":p=", $7) # add :p. to end off each $7 before the ;
} # close block
}1' input # define input file
所需输出制表符分隔
R_Index Chr Start End Ref Alt Detail.refGene Gene.refGene
1 chr1 948846 948846 - A dist=1 ISG15
2 chr1 948870 948870 C G NM_005101:c.-84C>G ISG15
3 chr1 948921 948921 T C NM_005101:c.-33T>C;NM_005101:c.-84C>G ISG15
4 chr1 949654 949654 A G . ISG15
R_Index Chr Start End Ref Alt Detail.refGene Gene.refGene
1 chr1 948846 948846 - A dist=1 ISG15
2 chr1 948870 948870 C G NM_005101:c.-84C>G:p.= ISG15
3 chr1 948921 948921 T C NM_005101:c.-33T>C;NM_005101:c.-84C>G:p.=p.= ISG15
4 chr1 949654 949654 A G . ISG15
R_Index Chr Start End Ref Alt Detail.refGene Gene.refGene
1 chr1 948846 948846 - A dist=1 ISG15
2 chr1 948870 948870 C G NM_005101:c.-84C>G:p.= ISG15
3 chr1 948921 948921 T C NM_005101:c.-33T>C:p.=;NM_005101:c.-84C>G:p.= ISG15
4 chr1 949654 949654 A G . ISG15
替换此项:
i=split($7,NM,";")
for (n=1; n<=i; n++) {
sub("$", ":p=", $7) # add :p. to end off each $7 before the ;
}
i=split($7,NM,“;”)
对于(n=1;n替换为:
i=split($7,NM,";")
for (n=1; n<=i; n++) {
sub("$", ":p=", $7) # add :p. to end off each $7 before the ;
}
i=split($7,NM,“;”)
对于(n=1;nwho提出了这些可怕的格式?它既不适合机器也不适合人类。抱歉,我尝试缩进代码以提高可读性,但不幸的是,文件类型是从仪器中获得的……我想我应该在excel中查看它,也许这会有所帮助。谢谢:).:p.=
在领带上流口水?:d太有趣了:)谁想出了这些可怕的格式?这既不利于机器也不利于人。对不起,我尝试缩进代码以提高可读性,但不幸的是,文件类型来自仪器。。。。我想也许我应该在excel中查看,也许这会有所帮助。谢谢:)。:p.=
在领带上流口水太好笑了:)