grep 如果字值大于值 [英] grep if word value greater than value

查看:218
本文介绍了grep 如果字值大于值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这样归档:

1       51710   .       C       A       .       clustered_events;contamination;germline_risk;read_position;t_lod        DP=1;ECNT=6;POP_AF=1.000e-03;P_GERMLINE=-1.372e-02;TLOD=4.20    GT:AD:AF:DP:F1R2:F2R1:MBQ:MFRL:MMQ:MPOS:PGT:PID:SA_MAP_AF:SA_POST_PROB  0/1:0,1:1.000:1:0,0:0,1:26:0,136:43:2:0|1:51637_C_T:0.990,0.00,1.00:0.025,0.028,0.947
19  27733067    .   A   G,C .   clustered_events;contamination;germline_risk;multiallelic   DP=60;ECNT=15;POP_AF=1.000e-03,1.000e-03;P_GERMLINE=-2.169e-04,-2.325e-04;TLOD=11.46,7.14   GT:AD:AF:DP:F1R2:F2R1:MBQ:MFRL:MMQ:MPOS:SA_MAP_AF:SA_POST_PROB  0/1/2:5,35,20:0.500,0.333:6:0,2,1:1,1,1:34,35:112,143,117:42,45:29,47:0.444,0.485,0.500:0.037,0.019,0.944
20  42199704    .   GGT G,GGTGGGTGGGTGTGTGT .   germline_risk   DP=100;ECNT=2;POP_AF=0.112,0.024;P_GERMLINE=-2.964e-04,-8.826e-06;TLOD=3.76,9.83    GT:AD:AF:DP:F1R2:F2R1:MBQ:MFRL:MMQ:MPOS:SA_MAP_AF:SA_POST_PROB  0/1/2:1,2,7:0.168,0.301:20:1,1,4:9,1,1:34,35:147,203,146:60,60:51,62:0.192,0.253,0.263:0.038,0.014,0.948

我想分两步 grep 行:

I want to grep lines on two steps:

具有 DP > 的行45.然后,在最后一列中的第一个 : 之后具有值的行 > 2

The lines that have DP > 45. Then, the lines that have value after first : in the last column > 2

因此,在第一行中,我们可以看到 DP 为 = 1,而最后一列中的第一个值是 : 之后的值 = 0

So, in the first line, we can see that DP is = 1 and the first value after : in the last column = 0

并且在第二行中,DP 是 = 60 并且在最后一列中的第一个值是 : 之后的值 = 5

And in the second line, DP is = 60 and the first value after : in the last column = 5

从上面的示例输入文件中,首先我们应该得到:

From the above example input file, first we should get:

19  27733067    .   A   G,C .   clustered_events;contamination;germline_risk;multiallelic   DP=60;ECNT=15;POP_AF=1.000e-03,1.000e-03;P_GERMLINE=-2.169e-04,-2.325e-04;TLOD=11.46,7.14   GT:AD:AF:DP:F1R2:F2R1:MBQ:MFRL:MMQ:MPOS:SA_MAP_AF:SA_POST_PROB  0/1/2:5,35,20:0.500,0.333:6:0,2,1:1,1,1:34,35:112,143,117:42,45:29,47:0.444,0.485,0.500:0.037,0.019,0.944
20  42199704    .   GGT G,GGTGGGTGGGTGTGTGT .   germline_risk   DP=100;ECNT=2;POP_AF=0.112,0.024;P_GERMLINE=-2.964e-04,-8.826e-06;TLOD=3.76,9.83    GT:AD:AF:DP:F1R2:F2R1:MBQ:MFRL:MMQ:MPOS:SA_MAP_AF:SA_POST_PROB  0/1/2:1,2,7:0.168,0.301:20:1,1,4:9,1,1:34,35:147,203,146:60,60:51,62:0.192,0.253,0.263:0.038,0.014,0.948

在第二个之后我们应该得到:

And after the second we should get:

19  27733067    .   A   G,C .   clustered_events;contamination;germline_risk;multiallelic   DP=60;ECNT=15;POP_AF=1.000e-03,1.000e-03;P_GERMLINE=-2.169e-04,-2.325e-04;TLOD=11.46,7.14   GT:AD:AF:DP:F1R2:F2R1:MBQ:MFRL:MMQ:MPOS:SA_MAP_AF:SA_POST_PROB  0/1/2:5,35,20:0.500,0.333:6:0,2,1:1,1,1:34,35:112,143,117:42,45:29,47:0.444,0.485,0.500:0.037,0.019,0.944
92,0.253,0.263:0.038,0.014,0.948

请问有什么帮助吗?

推荐答案

你可以试试看吗.

awk '
{
  split($8,array,"[;=]")
  if(array[1]=="DP" && array[2]>45){
    split($10,array1,"[:,]")
    if(array1[2]>2){
       print
    }
  }
}'  Input_file

说明:现在为上面的代码添加说明.

Explanation: Adding explanation for above code now.

awk '                                    ##Starting awk program here.
{                                        ##Starting block for statements here.
  split($8,array,"[;=]")                 ##Using awk out of box function split for splitting 8th field and saving it to array with delimiter ;=
  if(array[1]=="DP" && array[2]>45){     ##Checking condition if 1st element of array is DP and 2nd element value is greater than 45 then:
    split($10,array1,"[:,]")             ##Splitting 10th  field to array1 with delkimter : and , here.
    if(array1[2]>2){                     ##Checking condition if array1 2nd element if its value is greater than 2 then do following.
       print                             ##Printing the current line value here.
    }                                    ##Closing block for above if condition here.
  }                                      ##Closing block for previous if condition here.
}' Input_file                            ##Mentioning Input_file name here.

这篇关于grep 如果字值大于值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆