How to extract specific pattern from a file in HP-UX
Clash 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
awk sed grep perl hp-ux
add a comment |Â
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
awk sed grep perl hp-ux
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, trygrep -o '/oracle'
... else trysed -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
add a comment |Â
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
awk sed grep perl hp-ux
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
awk sed grep perl hp-ux
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, trygrep -o '/oracle'
... else trysed -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
add a comment |Â
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, trygrep -o '/oracle'
... else trysed -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
add a comment |Â
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").
add a comment |Â
up vote
-2
down vote
I found a command in google and it worked perfectly.
awk "/^/oracle$/" file_name
add a comment |Â
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").
add a comment |Â
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").
add a comment |Â
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").
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").
edited Dec 8 '17 at 8:54
answered Dec 7 '17 at 9:29
Murphy
1,7471517
1,7471517
add a comment |Â
add a comment |Â
up vote
-2
down vote
I found a command in google and it worked perfectly.
awk "/^/oracle$/" file_name
add a comment |Â
up vote
-2
down vote
I found a command in google and it worked perfectly.
awk "/^/oracle$/" file_name
add a comment |Â
up vote
-2
down vote
up vote
-2
down vote
I found a command in google and it worked perfectly.
awk "/^/oracle$/" file_name
I found a command in google and it worked perfectly.
awk "/^/oracle$/" file_name
edited Dec 8 '17 at 14:21
Stephen Rauch
3,248101227
3,248101227
answered Dec 8 '17 at 14:02
Pandu
2616
2616
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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, trygrep -o '/oracle'
... else trysed -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