Awk to print lines in file with multiple delimiters












1















I have a file that looks like:



chr1    1197592 .   C   A   .   .   DP=67;ECNT=1;NLOD=8.12  GT:AD:AF:F1R2   0/1:37,2:0.063:13,0
chr1 1355707 . G T . . DP=69;ECNT=1;NLOD=4.51 GT:AD:AF:F1R2 0/1:50,3:0.059:20,3
chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4
chr1 2550056 . TC CT . . DP=99;ECNT=1;NLOD=9.03 GT:AD:AF:F1R2 0/1:63,2:0.053:33,2


I would like to print the lines for which the 3rd value in the 10th column is greater than 0.06.



cat file.txt | cut -f 10 | cut -f 3 | awk -F':' '$3>0.06'


Will only give me:



0/1:37,2:0.063:13,0
0/1:30,2:0.089:12,4


And I would like the entire line. Can that be done with awk?










share|improve this question

























  • Since you're working with VCF files, an extremely complex format whose variety is not represented in this limited example, you might want to consider our sister site Bioinformatics for future questions, since the users there will be much more aware of the details of this format and how to deal with it.

    – terdon
    Jan 8 at 11:54











  • Thanks @terdon, i will consider it next time!

    – lindak
    Jan 8 at 12:15
















1















I have a file that looks like:



chr1    1197592 .   C   A   .   .   DP=67;ECNT=1;NLOD=8.12  GT:AD:AF:F1R2   0/1:37,2:0.063:13,0
chr1 1355707 . G T . . DP=69;ECNT=1;NLOD=4.51 GT:AD:AF:F1R2 0/1:50,3:0.059:20,3
chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4
chr1 2550056 . TC CT . . DP=99;ECNT=1;NLOD=9.03 GT:AD:AF:F1R2 0/1:63,2:0.053:33,2


I would like to print the lines for which the 3rd value in the 10th column is greater than 0.06.



cat file.txt | cut -f 10 | cut -f 3 | awk -F':' '$3>0.06'


Will only give me:



0/1:37,2:0.063:13,0
0/1:30,2:0.089:12,4


And I would like the entire line. Can that be done with awk?










share|improve this question

























  • Since you're working with VCF files, an extremely complex format whose variety is not represented in this limited example, you might want to consider our sister site Bioinformatics for future questions, since the users there will be much more aware of the details of this format and how to deal with it.

    – terdon
    Jan 8 at 11:54











  • Thanks @terdon, i will consider it next time!

    – lindak
    Jan 8 at 12:15














1












1








1


1






I have a file that looks like:



chr1    1197592 .   C   A   .   .   DP=67;ECNT=1;NLOD=8.12  GT:AD:AF:F1R2   0/1:37,2:0.063:13,0
chr1 1355707 . G T . . DP=69;ECNT=1;NLOD=4.51 GT:AD:AF:F1R2 0/1:50,3:0.059:20,3
chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4
chr1 2550056 . TC CT . . DP=99;ECNT=1;NLOD=9.03 GT:AD:AF:F1R2 0/1:63,2:0.053:33,2


I would like to print the lines for which the 3rd value in the 10th column is greater than 0.06.



cat file.txt | cut -f 10 | cut -f 3 | awk -F':' '$3>0.06'


Will only give me:



0/1:37,2:0.063:13,0
0/1:30,2:0.089:12,4


And I would like the entire line. Can that be done with awk?










share|improve this question
















I have a file that looks like:



chr1    1197592 .   C   A   .   .   DP=67;ECNT=1;NLOD=8.12  GT:AD:AF:F1R2   0/1:37,2:0.063:13,0
chr1 1355707 . G T . . DP=69;ECNT=1;NLOD=4.51 GT:AD:AF:F1R2 0/1:50,3:0.059:20,3
chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4
chr1 2550056 . TC CT . . DP=99;ECNT=1;NLOD=9.03 GT:AD:AF:F1R2 0/1:63,2:0.053:33,2


I would like to print the lines for which the 3rd value in the 10th column is greater than 0.06.



cat file.txt | cut -f 10 | cut -f 3 | awk -F':' '$3>0.06'


Will only give me:



0/1:37,2:0.063:13,0
0/1:30,2:0.089:12,4


And I would like the entire line. Can that be done with awk?







text-processing awk






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 8 at 11:55









terdon

129k32253430




129k32253430










asked Jan 8 at 11:13









lindaklindak

112




112













  • Since you're working with VCF files, an extremely complex format whose variety is not represented in this limited example, you might want to consider our sister site Bioinformatics for future questions, since the users there will be much more aware of the details of this format and how to deal with it.

    – terdon
    Jan 8 at 11:54











  • Thanks @terdon, i will consider it next time!

    – lindak
    Jan 8 at 12:15



















  • Since you're working with VCF files, an extremely complex format whose variety is not represented in this limited example, you might want to consider our sister site Bioinformatics for future questions, since the users there will be much more aware of the details of this format and how to deal with it.

    – terdon
    Jan 8 at 11:54











  • Thanks @terdon, i will consider it next time!

    – lindak
    Jan 8 at 12:15

















Since you're working with VCF files, an extremely complex format whose variety is not represented in this limited example, you might want to consider our sister site Bioinformatics for future questions, since the users there will be much more aware of the details of this format and how to deal with it.

– terdon
Jan 8 at 11:54





Since you're working with VCF files, an extremely complex format whose variety is not represented in this limited example, you might want to consider our sister site Bioinformatics for future questions, since the users there will be much more aware of the details of this format and how to deal with it.

– terdon
Jan 8 at 11:54













Thanks @terdon, i will consider it next time!

– lindak
Jan 8 at 12:15





Thanks @terdon, i will consider it next time!

– lindak
Jan 8 at 12:15










4 Answers
4






active

oldest

votes


















3














As soon as you start discarding data in a pipeline (which is what cut does), you can't get it back in a later stage of the same pipeline.



Instead,



$ awk 'split($10,a,":") && a[3] > 0.06' file
chr1 1197592 . C A . . DP=67;ECNT=1;NLOD=8.12 GT:AD:AF:F1R2 0/1:37,2:0.063:13,0
chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4


This takes the 10th whitespace-delimited field and splits it on colons into the array a. It prints the original line if the split() generated any elements in a and if the third element of a is greater than 0.06.



If the fields in the file are tab-delimited and if any field contains spaces, then use -F 't' with awk to make sure that it finds the right fields correctly (the given example data does not have any such issues as far as I can see).





Addressing the follow-up question in comments:



awk 'split($10,a,":") && a[3] > 0.06 && split($11,b,":") && b[3] > 0.01' file





share|improve this answer


























  • Will it work also if i have a column 11 with similar info as in 10 to filter on them both simultaneously? E.g. to print only lines where value 3 in column 10>0.06 and value 3 in column 11>0.01. Something like: awk '(split($10,a,":") && a[3] > 0.06) && (split($11,b,":") && b[3] > 0.01)'

    – lindak
    Jan 8 at 15:09













  • @lindak Yes, but the parentheses are optional there (unless you later want to change to (... && ...) || (... && ...)). See updated answer.

    – Kusalananda
    Jan 8 at 15:11













  • Great, thank you!

    – lindak
    Jan 8 at 15:14



















3














awk -F':' '$(NF-1) > 0.06 {print $0}' file


Just use ':' as separator and evaluate the penultimate column






share|improve this answer
























  • Thank you, it works for my example file, but my actual file has more columns which i never commented in the post, so my bad...

    – lindak
    Jan 8 at 12:09



















0














Having read the comments it's clear that your sample data doesn't match your actual data (and it's using spaces instead of TABs to begin with, which means that even the command output of your own device won't work), but having clobbered together a different input file like so:



cat file.txt
chr1 1197592 . C A . . DP=67;ECNT=1;NLOD=8.12 GT:AD:AF:F1R2 0/1:37,2:0.063:13,0 0/1:37,2:0.0005:13,0
chr1 1355707 . G T . . DP=69;ECNT=1;NLOD=4.51 GT:AD:AF:F1R2 0/1:50,3:0.059:20,3 0/1:50,3:0.0005:20,3
chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4 0/1:30,2:0.0015:12,4
chr1 2550056 . TC CT . . DP=99;ECNT=1;NLOD=9.03 GT:AD:AF:F1R2 0/1:63,2:0.053:33,2 0/1:63,2:0.0005:33,2


This will then output all lines matching both conditions:



awk -F"[  :]" '$15>0.06 && $19>0.001' file.txt
chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4 0/1:30,2:0.0015:12,4





share|improve this answer































    -1














    I have used below method to achieve the result



    for  i in `awk  '{print $NF}' file.txt | awk -F ":" '$3>"0.06"{print $0}'`; do awk -v i="$i" '$NF ==i{print $0}' file.txt ;done


    output



    chr1    1197592 .   C   A   .   .   DP=67;ECNT=1;NLOD=8.12  GT:AD:AF:F1R2   0/1:37,2:0.063:13,0
    chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4
    [root@praveen_linux_example ~]#





    share|improve this answer























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "106"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493204%2fawk-to-print-lines-in-file-with-multiple-delimiters%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      As soon as you start discarding data in a pipeline (which is what cut does), you can't get it back in a later stage of the same pipeline.



      Instead,



      $ awk 'split($10,a,":") && a[3] > 0.06' file
      chr1 1197592 . C A . . DP=67;ECNT=1;NLOD=8.12 GT:AD:AF:F1R2 0/1:37,2:0.063:13,0
      chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4


      This takes the 10th whitespace-delimited field and splits it on colons into the array a. It prints the original line if the split() generated any elements in a and if the third element of a is greater than 0.06.



      If the fields in the file are tab-delimited and if any field contains spaces, then use -F 't' with awk to make sure that it finds the right fields correctly (the given example data does not have any such issues as far as I can see).





      Addressing the follow-up question in comments:



      awk 'split($10,a,":") && a[3] > 0.06 && split($11,b,":") && b[3] > 0.01' file





      share|improve this answer


























      • Will it work also if i have a column 11 with similar info as in 10 to filter on them both simultaneously? E.g. to print only lines where value 3 in column 10>0.06 and value 3 in column 11>0.01. Something like: awk '(split($10,a,":") && a[3] > 0.06) && (split($11,b,":") && b[3] > 0.01)'

        – lindak
        Jan 8 at 15:09













      • @lindak Yes, but the parentheses are optional there (unless you later want to change to (... && ...) || (... && ...)). See updated answer.

        – Kusalananda
        Jan 8 at 15:11













      • Great, thank you!

        – lindak
        Jan 8 at 15:14
















      3














      As soon as you start discarding data in a pipeline (which is what cut does), you can't get it back in a later stage of the same pipeline.



      Instead,



      $ awk 'split($10,a,":") && a[3] > 0.06' file
      chr1 1197592 . C A . . DP=67;ECNT=1;NLOD=8.12 GT:AD:AF:F1R2 0/1:37,2:0.063:13,0
      chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4


      This takes the 10th whitespace-delimited field and splits it on colons into the array a. It prints the original line if the split() generated any elements in a and if the third element of a is greater than 0.06.



      If the fields in the file are tab-delimited and if any field contains spaces, then use -F 't' with awk to make sure that it finds the right fields correctly (the given example data does not have any such issues as far as I can see).





      Addressing the follow-up question in comments:



      awk 'split($10,a,":") && a[3] > 0.06 && split($11,b,":") && b[3] > 0.01' file





      share|improve this answer


























      • Will it work also if i have a column 11 with similar info as in 10 to filter on them both simultaneously? E.g. to print only lines where value 3 in column 10>0.06 and value 3 in column 11>0.01. Something like: awk '(split($10,a,":") && a[3] > 0.06) && (split($11,b,":") && b[3] > 0.01)'

        – lindak
        Jan 8 at 15:09













      • @lindak Yes, but the parentheses are optional there (unless you later want to change to (... && ...) || (... && ...)). See updated answer.

        – Kusalananda
        Jan 8 at 15:11













      • Great, thank you!

        – lindak
        Jan 8 at 15:14














      3












      3








      3







      As soon as you start discarding data in a pipeline (which is what cut does), you can't get it back in a later stage of the same pipeline.



      Instead,



      $ awk 'split($10,a,":") && a[3] > 0.06' file
      chr1 1197592 . C A . . DP=67;ECNT=1;NLOD=8.12 GT:AD:AF:F1R2 0/1:37,2:0.063:13,0
      chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4


      This takes the 10th whitespace-delimited field and splits it on colons into the array a. It prints the original line if the split() generated any elements in a and if the third element of a is greater than 0.06.



      If the fields in the file are tab-delimited and if any field contains spaces, then use -F 't' with awk to make sure that it finds the right fields correctly (the given example data does not have any such issues as far as I can see).





      Addressing the follow-up question in comments:



      awk 'split($10,a,":") && a[3] > 0.06 && split($11,b,":") && b[3] > 0.01' file





      share|improve this answer















      As soon as you start discarding data in a pipeline (which is what cut does), you can't get it back in a later stage of the same pipeline.



      Instead,



      $ awk 'split($10,a,":") && a[3] > 0.06' file
      chr1 1197592 . C A . . DP=67;ECNT=1;NLOD=8.12 GT:AD:AF:F1R2 0/1:37,2:0.063:13,0
      chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4


      This takes the 10th whitespace-delimited field and splits it on colons into the array a. It prints the original line if the split() generated any elements in a and if the third element of a is greater than 0.06.



      If the fields in the file are tab-delimited and if any field contains spaces, then use -F 't' with awk to make sure that it finds the right fields correctly (the given example data does not have any such issues as far as I can see).





      Addressing the follow-up question in comments:



      awk 'split($10,a,":") && a[3] > 0.06 && split($11,b,":") && b[3] > 0.01' file






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Jan 8 at 15:11

























      answered Jan 8 at 11:19









      KusalanandaKusalananda

      126k16239393




      126k16239393













      • Will it work also if i have a column 11 with similar info as in 10 to filter on them both simultaneously? E.g. to print only lines where value 3 in column 10>0.06 and value 3 in column 11>0.01. Something like: awk '(split($10,a,":") && a[3] > 0.06) && (split($11,b,":") && b[3] > 0.01)'

        – lindak
        Jan 8 at 15:09













      • @lindak Yes, but the parentheses are optional there (unless you later want to change to (... && ...) || (... && ...)). See updated answer.

        – Kusalananda
        Jan 8 at 15:11













      • Great, thank you!

        – lindak
        Jan 8 at 15:14



















      • Will it work also if i have a column 11 with similar info as in 10 to filter on them both simultaneously? E.g. to print only lines where value 3 in column 10>0.06 and value 3 in column 11>0.01. Something like: awk '(split($10,a,":") && a[3] > 0.06) && (split($11,b,":") && b[3] > 0.01)'

        – lindak
        Jan 8 at 15:09













      • @lindak Yes, but the parentheses are optional there (unless you later want to change to (... && ...) || (... && ...)). See updated answer.

        – Kusalananda
        Jan 8 at 15:11













      • Great, thank you!

        – lindak
        Jan 8 at 15:14

















      Will it work also if i have a column 11 with similar info as in 10 to filter on them both simultaneously? E.g. to print only lines where value 3 in column 10>0.06 and value 3 in column 11>0.01. Something like: awk '(split($10,a,":") && a[3] > 0.06) && (split($11,b,":") && b[3] > 0.01)'

      – lindak
      Jan 8 at 15:09







      Will it work also if i have a column 11 with similar info as in 10 to filter on them both simultaneously? E.g. to print only lines where value 3 in column 10>0.06 and value 3 in column 11>0.01. Something like: awk '(split($10,a,":") && a[3] > 0.06) && (split($11,b,":") && b[3] > 0.01)'

      – lindak
      Jan 8 at 15:09















      @lindak Yes, but the parentheses are optional there (unless you later want to change to (... && ...) || (... && ...)). See updated answer.

      – Kusalananda
      Jan 8 at 15:11







      @lindak Yes, but the parentheses are optional there (unless you later want to change to (... && ...) || (... && ...)). See updated answer.

      – Kusalananda
      Jan 8 at 15:11















      Great, thank you!

      – lindak
      Jan 8 at 15:14





      Great, thank you!

      – lindak
      Jan 8 at 15:14













      3














      awk -F':' '$(NF-1) > 0.06 {print $0}' file


      Just use ':' as separator and evaluate the penultimate column






      share|improve this answer
























      • Thank you, it works for my example file, but my actual file has more columns which i never commented in the post, so my bad...

        – lindak
        Jan 8 at 12:09
















      3














      awk -F':' '$(NF-1) > 0.06 {print $0}' file


      Just use ':' as separator and evaluate the penultimate column






      share|improve this answer
























      • Thank you, it works for my example file, but my actual file has more columns which i never commented in the post, so my bad...

        – lindak
        Jan 8 at 12:09














      3












      3








      3







      awk -F':' '$(NF-1) > 0.06 {print $0}' file


      Just use ':' as separator and evaluate the penultimate column






      share|improve this answer













      awk -F':' '$(NF-1) > 0.06 {print $0}' file


      Just use ':' as separator and evaluate the penultimate column







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Jan 8 at 11:27









      Emilio GalarragaEmilio Galarraga

      51929




      51929













      • Thank you, it works for my example file, but my actual file has more columns which i never commented in the post, so my bad...

        – lindak
        Jan 8 at 12:09



















      • Thank you, it works for my example file, but my actual file has more columns which i never commented in the post, so my bad...

        – lindak
        Jan 8 at 12:09

















      Thank you, it works for my example file, but my actual file has more columns which i never commented in the post, so my bad...

      – lindak
      Jan 8 at 12:09





      Thank you, it works for my example file, but my actual file has more columns which i never commented in the post, so my bad...

      – lindak
      Jan 8 at 12:09











      0














      Having read the comments it's clear that your sample data doesn't match your actual data (and it's using spaces instead of TABs to begin with, which means that even the command output of your own device won't work), but having clobbered together a different input file like so:



      cat file.txt
      chr1 1197592 . C A . . DP=67;ECNT=1;NLOD=8.12 GT:AD:AF:F1R2 0/1:37,2:0.063:13,0 0/1:37,2:0.0005:13,0
      chr1 1355707 . G T . . DP=69;ECNT=1;NLOD=4.51 GT:AD:AF:F1R2 0/1:50,3:0.059:20,3 0/1:50,3:0.0005:20,3
      chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4 0/1:30,2:0.0015:12,4
      chr1 2550056 . TC CT . . DP=99;ECNT=1;NLOD=9.03 GT:AD:AF:F1R2 0/1:63,2:0.053:33,2 0/1:63,2:0.0005:33,2


      This will then output all lines matching both conditions:



      awk -F"[  :]" '$15>0.06 && $19>0.001' file.txt
      chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4 0/1:30,2:0.0015:12,4





      share|improve this answer




























        0














        Having read the comments it's clear that your sample data doesn't match your actual data (and it's using spaces instead of TABs to begin with, which means that even the command output of your own device won't work), but having clobbered together a different input file like so:



        cat file.txt
        chr1 1197592 . C A . . DP=67;ECNT=1;NLOD=8.12 GT:AD:AF:F1R2 0/1:37,2:0.063:13,0 0/1:37,2:0.0005:13,0
        chr1 1355707 . G T . . DP=69;ECNT=1;NLOD=4.51 GT:AD:AF:F1R2 0/1:50,3:0.059:20,3 0/1:50,3:0.0005:20,3
        chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4 0/1:30,2:0.0015:12,4
        chr1 2550056 . TC CT . . DP=99;ECNT=1;NLOD=9.03 GT:AD:AF:F1R2 0/1:63,2:0.053:33,2 0/1:63,2:0.0005:33,2


        This will then output all lines matching both conditions:



        awk -F"[  :]" '$15>0.06 && $19>0.001' file.txt
        chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4 0/1:30,2:0.0015:12,4





        share|improve this answer


























          0












          0








          0







          Having read the comments it's clear that your sample data doesn't match your actual data (and it's using spaces instead of TABs to begin with, which means that even the command output of your own device won't work), but having clobbered together a different input file like so:



          cat file.txt
          chr1 1197592 . C A . . DP=67;ECNT=1;NLOD=8.12 GT:AD:AF:F1R2 0/1:37,2:0.063:13,0 0/1:37,2:0.0005:13,0
          chr1 1355707 . G T . . DP=69;ECNT=1;NLOD=4.51 GT:AD:AF:F1R2 0/1:50,3:0.059:20,3 0/1:50,3:0.0005:20,3
          chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4 0/1:30,2:0.0015:12,4
          chr1 2550056 . TC CT . . DP=99;ECNT=1;NLOD=9.03 GT:AD:AF:F1R2 0/1:63,2:0.053:33,2 0/1:63,2:0.0005:33,2


          This will then output all lines matching both conditions:



          awk -F"[  :]" '$15>0.06 && $19>0.001' file.txt
          chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4 0/1:30,2:0.0015:12,4





          share|improve this answer













          Having read the comments it's clear that your sample data doesn't match your actual data (and it's using spaces instead of TABs to begin with, which means that even the command output of your own device won't work), but having clobbered together a different input file like so:



          cat file.txt
          chr1 1197592 . C A . . DP=67;ECNT=1;NLOD=8.12 GT:AD:AF:F1R2 0/1:37,2:0.063:13,0 0/1:37,2:0.0005:13,0
          chr1 1355707 . G T . . DP=69;ECNT=1;NLOD=4.51 GT:AD:AF:F1R2 0/1:50,3:0.059:20,3 0/1:50,3:0.0005:20,3
          chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4 0/1:30,2:0.0015:12,4
          chr1 2550056 . TC CT . . DP=99;ECNT=1;NLOD=9.03 GT:AD:AF:F1R2 0/1:63,2:0.053:33,2 0/1:63,2:0.0005:33,2


          This will then output all lines matching both conditions:



          awk -F"[  :]" '$15>0.06 && $19>0.001' file.txt
          chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4 0/1:30,2:0.0015:12,4






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 8 at 16:17









          tinktink

          4,35211220




          4,35211220























              -1














              I have used below method to achieve the result



              for  i in `awk  '{print $NF}' file.txt | awk -F ":" '$3>"0.06"{print $0}'`; do awk -v i="$i" '$NF ==i{print $0}' file.txt ;done


              output



              chr1    1197592 .   C   A   .   .   DP=67;ECNT=1;NLOD=8.12  GT:AD:AF:F1R2   0/1:37,2:0.063:13,0
              chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4
              [root@praveen_linux_example ~]#





              share|improve this answer




























                -1














                I have used below method to achieve the result



                for  i in `awk  '{print $NF}' file.txt | awk -F ":" '$3>"0.06"{print $0}'`; do awk -v i="$i" '$NF ==i{print $0}' file.txt ;done


                output



                chr1    1197592 .   C   A   .   .   DP=67;ECNT=1;NLOD=8.12  GT:AD:AF:F1R2   0/1:37,2:0.063:13,0
                chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4
                [root@praveen_linux_example ~]#





                share|improve this answer


























                  -1












                  -1








                  -1







                  I have used below method to achieve the result



                  for  i in `awk  '{print $NF}' file.txt | awk -F ":" '$3>"0.06"{print $0}'`; do awk -v i="$i" '$NF ==i{print $0}' file.txt ;done


                  output



                  chr1    1197592 .   C   A   .   .   DP=67;ECNT=1;NLOD=8.12  GT:AD:AF:F1R2   0/1:37,2:0.063:13,0
                  chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4
                  [root@praveen_linux_example ~]#





                  share|improve this answer













                  I have used below method to achieve the result



                  for  i in `awk  '{print $NF}' file.txt | awk -F ":" '$3>"0.06"{print $0}'`; do awk -v i="$i" '$NF ==i{print $0}' file.txt ;done


                  output



                  chr1    1197592 .   C   A   .   .   DP=67;ECNT=1;NLOD=8.12  GT:AD:AF:F1R2   0/1:37,2:0.063:13,0
                  chr1 1641723 . TC T . . DP=59;ECNT=1;NLOD=2.40 GT:AD:AF:F1R2 0/1:30,2:0.089:12,4
                  [root@praveen_linux_example ~]#






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 8 at 15:49









                  Praveen Kumar BSPraveen Kumar BS

                  1,356138




                  1,356138






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493204%2fawk-to-print-lines-in-file-with-multiple-delimiters%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      How do I know what Microsoft account the skydrive app is syncing to?

                      When does type information flow backwards in C++?

                      Grease: Live!