grep the line contains only the match

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have the below file for example,



Hello world cheers
Hello world
Hi Hello world
Hi Hello world, How are you?


I would like to grep the line which contains only the Hello world with the line number.







share|improve this question


















  • 1




    How will you be using the line number later? If you are going to extract or change the line by its line number, then it's better to do so in one go instead of calling two utilities in sequence (getting the line number, then do something with that line).
    – Kusalananda
    Aug 18 at 20:30











  • @Kusalananda .. Thanks...as of now, i have requirement only to log these details.
    – fini r
    Aug 18 at 20:49






  • 1




    stackoverflow.com/questions/4709912/…
    – Julien Lopez
    Aug 18 at 22:13










  • Possible duplicate of grep to fetch whole line
    – roaima
    Aug 20 at 16:56














up vote
0
down vote

favorite












I have the below file for example,



Hello world cheers
Hello world
Hi Hello world
Hi Hello world, How are you?


I would like to grep the line which contains only the Hello world with the line number.







share|improve this question


















  • 1




    How will you be using the line number later? If you are going to extract or change the line by its line number, then it's better to do so in one go instead of calling two utilities in sequence (getting the line number, then do something with that line).
    – Kusalananda
    Aug 18 at 20:30











  • @Kusalananda .. Thanks...as of now, i have requirement only to log these details.
    – fini r
    Aug 18 at 20:49






  • 1




    stackoverflow.com/questions/4709912/…
    – Julien Lopez
    Aug 18 at 22:13










  • Possible duplicate of grep to fetch whole line
    – roaima
    Aug 20 at 16:56












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have the below file for example,



Hello world cheers
Hello world
Hi Hello world
Hi Hello world, How are you?


I would like to grep the line which contains only the Hello world with the line number.







share|improve this question














I have the below file for example,



Hello world cheers
Hello world
Hi Hello world
Hi Hello world, How are you?


I would like to grep the line which contains only the Hello world with the line number.









share|improve this question













share|improve this question




share|improve this question








edited Aug 18 at 19:04









SivaPrasath

1




1










asked Aug 18 at 19:03









fini r

124




124







  • 1




    How will you be using the line number later? If you are going to extract or change the line by its line number, then it's better to do so in one go instead of calling two utilities in sequence (getting the line number, then do something with that line).
    – Kusalananda
    Aug 18 at 20:30











  • @Kusalananda .. Thanks...as of now, i have requirement only to log these details.
    – fini r
    Aug 18 at 20:49






  • 1




    stackoverflow.com/questions/4709912/…
    – Julien Lopez
    Aug 18 at 22:13










  • Possible duplicate of grep to fetch whole line
    – roaima
    Aug 20 at 16:56












  • 1




    How will you be using the line number later? If you are going to extract or change the line by its line number, then it's better to do so in one go instead of calling two utilities in sequence (getting the line number, then do something with that line).
    – Kusalananda
    Aug 18 at 20:30











  • @Kusalananda .. Thanks...as of now, i have requirement only to log these details.
    – fini r
    Aug 18 at 20:49






  • 1




    stackoverflow.com/questions/4709912/…
    – Julien Lopez
    Aug 18 at 22:13










  • Possible duplicate of grep to fetch whole line
    – roaima
    Aug 20 at 16:56







1




1




How will you be using the line number later? If you are going to extract or change the line by its line number, then it's better to do so in one go instead of calling two utilities in sequence (getting the line number, then do something with that line).
– Kusalananda
Aug 18 at 20:30





How will you be using the line number later? If you are going to extract or change the line by its line number, then it's better to do so in one go instead of calling two utilities in sequence (getting the line number, then do something with that line).
– Kusalananda
Aug 18 at 20:30













@Kusalananda .. Thanks...as of now, i have requirement only to log these details.
– fini r
Aug 18 at 20:49




@Kusalananda .. Thanks...as of now, i have requirement only to log these details.
– fini r
Aug 18 at 20:49




1




1




stackoverflow.com/questions/4709912/…
– Julien Lopez
Aug 18 at 22:13




stackoverflow.com/questions/4709912/…
– Julien Lopez
Aug 18 at 22:13












Possible duplicate of grep to fetch whole line
– roaima
Aug 20 at 16:56




Possible duplicate of grep to fetch whole line
– roaima
Aug 20 at 16:56










1 Answer
1






active

oldest

votes

















up vote
10
down vote



accepted










Try this,



grep -nx "Hello world" fileName



  • -n will print the line number


  • -x Select only those matches that exactly match the whole line





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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    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%2f463396%2fgrep-the-line-contains-only-the-match%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    10
    down vote



    accepted










    Try this,



    grep -nx "Hello world" fileName



    • -n will print the line number


    • -x Select only those matches that exactly match the whole line





    share|improve this answer
























      up vote
      10
      down vote



      accepted










      Try this,



      grep -nx "Hello world" fileName



      • -n will print the line number


      • -x Select only those matches that exactly match the whole line





      share|improve this answer






















        up vote
        10
        down vote



        accepted







        up vote
        10
        down vote



        accepted






        Try this,



        grep -nx "Hello world" fileName



        • -n will print the line number


        • -x Select only those matches that exactly match the whole line





        share|improve this answer












        Try this,



        grep -nx "Hello world" fileName



        • -n will print the line number


        • -x Select only those matches that exactly match the whole line






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 18 at 19:06









        SivaPrasath

        1




        1



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f463396%2fgrep-the-line-contains-only-the-match%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            Installing NextGIS Connect into QGIS 3?

            One-line joke