print entire line after an awk and grep












0














I need to search multiple patterns on the third column of a file, and then print the whole line.



I am using this one below but how do I get it to print the whole line where there is a match?



awk '{print $3}' file | egrep -w "S|M|D"









share|improve this question







New contributor




hayabusa99 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • please click edit and add few lines of input and expected output - some line should match and others shouldn't... this will help to add clarity to question as well as act as test data for those who wish to answer your question
    – Sundeep
    2 days ago


















0














I need to search multiple patterns on the third column of a file, and then print the whole line.



I am using this one below but how do I get it to print the whole line where there is a match?



awk '{print $3}' file | egrep -w "S|M|D"









share|improve this question







New contributor




hayabusa99 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • please click edit and add few lines of input and expected output - some line should match and others shouldn't... this will help to add clarity to question as well as act as test data for those who wish to answer your question
    – Sundeep
    2 days ago
















0












0








0







I need to search multiple patterns on the third column of a file, and then print the whole line.



I am using this one below but how do I get it to print the whole line where there is a match?



awk '{print $3}' file | egrep -w "S|M|D"









share|improve this question







New contributor




hayabusa99 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I need to search multiple patterns on the third column of a file, and then print the whole line.



I am using this one below but how do I get it to print the whole line where there is a match?



awk '{print $3}' file | egrep -w "S|M|D"






shell-script awk scripting






share|improve this question







New contributor




hayabusa99 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




hayabusa99 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




hayabusa99 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









hayabusa99hayabusa99

31




31




New contributor




hayabusa99 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





hayabusa99 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






hayabusa99 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • please click edit and add few lines of input and expected output - some line should match and others shouldn't... this will help to add clarity to question as well as act as test data for those who wish to answer your question
    – Sundeep
    2 days ago




















  • please click edit and add few lines of input and expected output - some line should match and others shouldn't... this will help to add clarity to question as well as act as test data for those who wish to answer your question
    – Sundeep
    2 days ago


















please click edit and add few lines of input and expected output - some line should match and others shouldn't... this will help to add clarity to question as well as act as test data for those who wish to answer your question
– Sundeep
2 days ago






please click edit and add few lines of input and expected output - some line should match and others shouldn't... this will help to add clarity to question as well as act as test data for those who wish to answer your question
– Sundeep
2 days ago












3 Answers
3






active

oldest

votes


















3














I think your requirement just needs awk and not a combination with grep. If you are looking to print the whole line where the third column matches any of those letters, you need to do



awk '$3 ~ /^(S|M|D)$/' file





share|improve this answer

















  • 1




    since it is single character, you can also use [SMD]
    – Sundeep
    2 days ago










  • is this going to search for the exact match? like grep -w does?
    – hayabusa99
    2 days ago










  • It look like it works. Thanks!
    – hayabusa99
    2 days ago



















1














To extract the lines whose 3rd whitespace-delimited field is exactly S, M or D, use one of



awk '$3 ~ /^[SMD]$/' file


or, using string matching rather than regular expression matching,



awk '$3 == "S" || $3 == "M" || $3 == "D"' file


A condition without a corresponding block will act as if its block simply was { print }.






share|improve this answer





























    0














    awk '$3 ~ /^S/||/^M/||/^D/{print $0}' filename





    share|improve this answer





















    • The way this parses out will match column 3 starting with an S, or column 1 starting with an M or D -- it misses column 3 M/D and it incorrectly includes the column 1 matches.
      – Jeff Schaller
      8 hours ago











    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
    });


    }
    });






    hayabusa99 is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492952%2fprint-entire-line-after-an-awk-and-grep%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    I think your requirement just needs awk and not a combination with grep. If you are looking to print the whole line where the third column matches any of those letters, you need to do



    awk '$3 ~ /^(S|M|D)$/' file





    share|improve this answer

















    • 1




      since it is single character, you can also use [SMD]
      – Sundeep
      2 days ago










    • is this going to search for the exact match? like grep -w does?
      – hayabusa99
      2 days ago










    • It look like it works. Thanks!
      – hayabusa99
      2 days ago
















    3














    I think your requirement just needs awk and not a combination with grep. If you are looking to print the whole line where the third column matches any of those letters, you need to do



    awk '$3 ~ /^(S|M|D)$/' file





    share|improve this answer

















    • 1




      since it is single character, you can also use [SMD]
      – Sundeep
      2 days ago










    • is this going to search for the exact match? like grep -w does?
      – hayabusa99
      2 days ago










    • It look like it works. Thanks!
      – hayabusa99
      2 days ago














    3












    3








    3






    I think your requirement just needs awk and not a combination with grep. If you are looking to print the whole line where the third column matches any of those letters, you need to do



    awk '$3 ~ /^(S|M|D)$/' file





    share|improve this answer












    I think your requirement just needs awk and not a combination with grep. If you are looking to print the whole line where the third column matches any of those letters, you need to do



    awk '$3 ~ /^(S|M|D)$/' file






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 2 days ago









    InianInian

    3,935824




    3,935824








    • 1




      since it is single character, you can also use [SMD]
      – Sundeep
      2 days ago










    • is this going to search for the exact match? like grep -w does?
      – hayabusa99
      2 days ago










    • It look like it works. Thanks!
      – hayabusa99
      2 days ago














    • 1




      since it is single character, you can also use [SMD]
      – Sundeep
      2 days ago










    • is this going to search for the exact match? like grep -w does?
      – hayabusa99
      2 days ago










    • It look like it works. Thanks!
      – hayabusa99
      2 days ago








    1




    1




    since it is single character, you can also use [SMD]
    – Sundeep
    2 days ago




    since it is single character, you can also use [SMD]
    – Sundeep
    2 days ago












    is this going to search for the exact match? like grep -w does?
    – hayabusa99
    2 days ago




    is this going to search for the exact match? like grep -w does?
    – hayabusa99
    2 days ago












    It look like it works. Thanks!
    – hayabusa99
    2 days ago




    It look like it works. Thanks!
    – hayabusa99
    2 days ago













    1














    To extract the lines whose 3rd whitespace-delimited field is exactly S, M or D, use one of



    awk '$3 ~ /^[SMD]$/' file


    or, using string matching rather than regular expression matching,



    awk '$3 == "S" || $3 == "M" || $3 == "D"' file


    A condition without a corresponding block will act as if its block simply was { print }.






    share|improve this answer


























      1














      To extract the lines whose 3rd whitespace-delimited field is exactly S, M or D, use one of



      awk '$3 ~ /^[SMD]$/' file


      or, using string matching rather than regular expression matching,



      awk '$3 == "S" || $3 == "M" || $3 == "D"' file


      A condition without a corresponding block will act as if its block simply was { print }.






      share|improve this answer
























        1












        1








        1






        To extract the lines whose 3rd whitespace-delimited field is exactly S, M or D, use one of



        awk '$3 ~ /^[SMD]$/' file


        or, using string matching rather than regular expression matching,



        awk '$3 == "S" || $3 == "M" || $3 == "D"' file


        A condition without a corresponding block will act as if its block simply was { print }.






        share|improve this answer












        To extract the lines whose 3rd whitespace-delimited field is exactly S, M or D, use one of



        awk '$3 ~ /^[SMD]$/' file


        or, using string matching rather than regular expression matching,



        awk '$3 == "S" || $3 == "M" || $3 == "D"' file


        A condition without a corresponding block will act as if its block simply was { print }.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        KusalanandaKusalananda

        123k16232379




        123k16232379























            0














            awk '$3 ~ /^S/||/^M/||/^D/{print $0}' filename





            share|improve this answer





















            • The way this parses out will match column 3 starting with an S, or column 1 starting with an M or D -- it misses column 3 M/D and it incorrectly includes the column 1 matches.
              – Jeff Schaller
              8 hours ago
















            0














            awk '$3 ~ /^S/||/^M/||/^D/{print $0}' filename





            share|improve this answer





















            • The way this parses out will match column 3 starting with an S, or column 1 starting with an M or D -- it misses column 3 M/D and it incorrectly includes the column 1 matches.
              – Jeff Schaller
              8 hours ago














            0












            0








            0






            awk '$3 ~ /^S/||/^M/||/^D/{print $0}' filename





            share|improve this answer












            awk '$3 ~ /^S/||/^M/||/^D/{print $0}' filename






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 10 hours ago









            Praveen Kumar BSPraveen Kumar BS

            1,248138




            1,248138












            • The way this parses out will match column 3 starting with an S, or column 1 starting with an M or D -- it misses column 3 M/D and it incorrectly includes the column 1 matches.
              – Jeff Schaller
              8 hours ago


















            • The way this parses out will match column 3 starting with an S, or column 1 starting with an M or D -- it misses column 3 M/D and it incorrectly includes the column 1 matches.
              – Jeff Schaller
              8 hours ago
















            The way this parses out will match column 3 starting with an S, or column 1 starting with an M or D -- it misses column 3 M/D and it incorrectly includes the column 1 matches.
            – Jeff Schaller
            8 hours ago




            The way this parses out will match column 3 starting with an S, or column 1 starting with an M or D -- it misses column 3 M/D and it incorrectly includes the column 1 matches.
            – Jeff Schaller
            8 hours ago










            hayabusa99 is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            hayabusa99 is a new contributor. Be nice, and check out our Code of Conduct.













            hayabusa99 is a new contributor. Be nice, and check out our Code of Conduct.












            hayabusa99 is a new contributor. Be nice, and check out our Code of Conduct.
















            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f492952%2fprint-entire-line-after-an-awk-and-grep%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 to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

            is 'sed' thread safe

            How to make a Squid Proxy server?