How to extract specific pattern from a file in HP-UX

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











up vote
1
down vote

favorite












I would to like extract the pattern "/oracle" from a file.



I tried with "grep -w" command but it returned all the lines which have oracle word.



I need to extract only /oracle. Please tell me if any command grep,awk,sed gives my output



File Content:



 /oracle
/oracle/client
/oracle/T02
/oracle/P02
/oracle/R03






share|improve this question




















  • are there lines without /oracle in them? can there be more than one match in a line? what if you have matches like /oracles? if you have -o option, try grep -o '/oracle'... else try sed -n 's#.*(/oracle).*#1#p'
    – Sundeep
    Dec 7 '17 at 9:00










  • Yes ther are lines without oracle as well. No One match in a line.
    – Pandu
    Dec 7 '17 at 9:12










  • then you should change your sample data to include those other lines as well... and add complete expected output for clarity..
    – Sundeep
    Dec 7 '17 at 9:18














up vote
1
down vote

favorite












I would to like extract the pattern "/oracle" from a file.



I tried with "grep -w" command but it returned all the lines which have oracle word.



I need to extract only /oracle. Please tell me if any command grep,awk,sed gives my output



File Content:



 /oracle
/oracle/client
/oracle/T02
/oracle/P02
/oracle/R03






share|improve this question




















  • are there lines without /oracle in them? can there be more than one match in a line? what if you have matches like /oracles? if you have -o option, try grep -o '/oracle'... else try sed -n 's#.*(/oracle).*#1#p'
    – Sundeep
    Dec 7 '17 at 9:00










  • Yes ther are lines without oracle as well. No One match in a line.
    – Pandu
    Dec 7 '17 at 9:12










  • then you should change your sample data to include those other lines as well... and add complete expected output for clarity..
    – Sundeep
    Dec 7 '17 at 9:18












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I would to like extract the pattern "/oracle" from a file.



I tried with "grep -w" command but it returned all the lines which have oracle word.



I need to extract only /oracle. Please tell me if any command grep,awk,sed gives my output



File Content:



 /oracle
/oracle/client
/oracle/T02
/oracle/P02
/oracle/R03






share|improve this question












I would to like extract the pattern "/oracle" from a file.



I tried with "grep -w" command but it returned all the lines which have oracle word.



I need to extract only /oracle. Please tell me if any command grep,awk,sed gives my output



File Content:



 /oracle
/oracle/client
/oracle/T02
/oracle/P02
/oracle/R03








share|improve this question











share|improve this question




share|improve this question










asked Dec 7 '17 at 8:45









Pandu

2616




2616











  • are there lines without /oracle in them? can there be more than one match in a line? what if you have matches like /oracles? if you have -o option, try grep -o '/oracle'... else try sed -n 's#.*(/oracle).*#1#p'
    – Sundeep
    Dec 7 '17 at 9:00










  • Yes ther are lines without oracle as well. No One match in a line.
    – Pandu
    Dec 7 '17 at 9:12










  • then you should change your sample data to include those other lines as well... and add complete expected output for clarity..
    – Sundeep
    Dec 7 '17 at 9:18
















  • are there lines without /oracle in them? can there be more than one match in a line? what if you have matches like /oracles? if you have -o option, try grep -o '/oracle'... else try sed -n 's#.*(/oracle).*#1#p'
    – Sundeep
    Dec 7 '17 at 9:00










  • Yes ther are lines without oracle as well. No One match in a line.
    – Pandu
    Dec 7 '17 at 9:12










  • then you should change your sample data to include those other lines as well... and add complete expected output for clarity..
    – Sundeep
    Dec 7 '17 at 9:18















are there lines without /oracle in them? can there be more than one match in a line? what if you have matches like /oracles? if you have -o option, try grep -o '/oracle'... else try sed -n 's#.*(/oracle).*#1#p'
– Sundeep
Dec 7 '17 at 9:00




are there lines without /oracle in them? can there be more than one match in a line? what if you have matches like /oracles? if you have -o option, try grep -o '/oracle'... else try sed -n 's#.*(/oracle).*#1#p'
– Sundeep
Dec 7 '17 at 9:00












Yes ther are lines without oracle as well. No One match in a line.
– Pandu
Dec 7 '17 at 9:12




Yes ther are lines without oracle as well. No One match in a line.
– Pandu
Dec 7 '17 at 9:12












then you should change your sample data to include those other lines as well... and add complete expected output for clarity..
– Sundeep
Dec 7 '17 at 9:18




then you should change your sample data to include those other lines as well... and add complete expected output for clarity..
– Sundeep
Dec 7 '17 at 9:18










2 Answers
2






active

oldest

votes

















up vote
0
down vote













Try grep -x instead of grep -w:



$ grep -x "/oracle" test.txt
/oracle


Tested on Linux, but should apply to HP-UX, too. Else look at the manpage for "line-regexp" (instead of "word-regexp").






share|improve this answer





























    up vote
    -2
    down vote













    I found a command in google and it worked perfectly.



    awk "/^/oracle$/" file_name





    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%2f409424%2fhow-to-extract-specific-pattern-from-a-file-in-hp-ux%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      Try grep -x instead of grep -w:



      $ grep -x "/oracle" test.txt
      /oracle


      Tested on Linux, but should apply to HP-UX, too. Else look at the manpage for "line-regexp" (instead of "word-regexp").






      share|improve this answer


























        up vote
        0
        down vote













        Try grep -x instead of grep -w:



        $ grep -x "/oracle" test.txt
        /oracle


        Tested on Linux, but should apply to HP-UX, too. Else look at the manpage for "line-regexp" (instead of "word-regexp").






        share|improve this answer
























          up vote
          0
          down vote










          up vote
          0
          down vote









          Try grep -x instead of grep -w:



          $ grep -x "/oracle" test.txt
          /oracle


          Tested on Linux, but should apply to HP-UX, too. Else look at the manpage for "line-regexp" (instead of "word-regexp").






          share|improve this answer














          Try grep -x instead of grep -w:



          $ grep -x "/oracle" test.txt
          /oracle


          Tested on Linux, but should apply to HP-UX, too. Else look at the manpage for "line-regexp" (instead of "word-regexp").







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 8 '17 at 8:54

























          answered Dec 7 '17 at 9:29









          Murphy

          1,7471517




          1,7471517






















              up vote
              -2
              down vote













              I found a command in google and it worked perfectly.



              awk "/^/oracle$/" file_name





              share|improve this answer


























                up vote
                -2
                down vote













                I found a command in google and it worked perfectly.



                awk "/^/oracle$/" file_name





                share|improve this answer
























                  up vote
                  -2
                  down vote










                  up vote
                  -2
                  down vote









                  I found a command in google and it worked perfectly.



                  awk "/^/oracle$/" file_name





                  share|improve this answer














                  I found a command in google and it worked perfectly.



                  awk "/^/oracle$/" file_name






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 8 '17 at 14:21









                  Stephen Rauch

                  3,248101227




                  3,248101227










                  answered Dec 8 '17 at 14:02









                  Pandu

                  2616




                  2616



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409424%2fhow-to-extract-specific-pattern-from-a-file-in-hp-ux%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Displaying single band from multi-band raster using QGIS

                      How many registers does an x86_64 CPU actually have?