1

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
  • 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
0

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").

-2

I found a command in google and it worked perfectly.

awk "/^\/oracle$/" file_name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.