Extract a part of grep output


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Extract a part of grep output
# 1  
Old 10-24-2019
Extract a part of grep output

Hi,
On AIX 7
I have :
Code:
grep 's_ohs_instance_loc' $CONTEXT_FILE
        
<ohs_instance_loc oa_var="s_ohs_instance_loc">/u01/appl_top/env/fs1/FMW_Home/webtier/instances/EBS_web_env_OHS1</ohs_instance_loc>

But I need only this part: /u01/appl_top/env/fs1/FMW_Home/webtier/instances/EBS_web_env_OHS1

which is between > and < How can I have it?

Thanks

Last edited by Yoda; 10-24-2019 at 10:40 AM..
# 2  
Old 10-24-2019
Hi, try;
Code:
awk '/s_ohs_instance_loc/{print $2}' RS=\< FS=\> "$CONTEXT_FILE"


Last edited by Scrutinizer; 10-24-2019 at 12:48 PM..
# 3  
Old 10-24-2019
Here is one as well.
Code:
awk '/s_ohs_instance_loc/ && match($0,/>.*</) { print substr($0,RSTART+1,RLENGTH-2) } '

Regards
Peasant.
# 4  
Old 10-24-2019
Thanks to all.
# 5  
Old 10-24-2019
Quote:
Originally Posted by Peasant
Here is one as well.
Code:
awk '/s_ohs_instance_loc/ && match($0,/>.*</) { print substr($0,RSTART+1,RLENGTH-2) } '

[..]
One thing to note is that this will work as long as there are no other tags on the line where the match occurs..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to extract only relevant part from a sentence?

Hello All, I have a file with details such as below. How do i extract only the host and port ? eg: dbs.ads.com 1521 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dbs.ads.com)(PORT=1521))(CONNECT_DATA=(SID=vug)))... (5 Replies)
Discussion started by: JohnJacobChacko
5 Replies

2. UNIX for Advanced & Expert Users

Need help to extract part of the string

Hi, I have a string with name as 20140412-s1-Potopolive_promos_20140412. So I want to extract only Potopolive string. Could you please help me the command. O/p : Potopolive Thx in advance (5 Replies)
Discussion started by: lkeswar
5 Replies

3. Shell Programming and Scripting

Extract part of file

Hello All, I need to extract part of a file into a new file My file is Define schema xxxxxx Insert into table ( a ,b ,c ,d ) values ( 1, 2, 3, (15 Replies)
Discussion started by: nnani
15 Replies

4. Shell Programming and Scripting

Extract part of a string

I have a file with 100s of lines of text. I want to perform an extraction of this line: Info bpzs(pid=2652) using 1000 bits I have not been able to extract it. Should I try expr match or is there another method? This line has data both in front of and in back of it. I do not have grep -o... (5 Replies)
Discussion started by: newbie2010
5 Replies

5. Shell Programming and Scripting

Help with extract particular part of data

Input file <data> <temporary>qe2qrqerq qwewqeqwrqwrq qrerwrewrwer </temporary> </data> <sample>@!@##%#</sample> <info>12345</info> <content>2313214141454</content> <data> <temporary>qe2qrqerq qrerwrewrwer </temporary> <content>123214214523</content> </data>... (5 Replies)
Discussion started by: perl_beginner
5 Replies

6. Shell Programming and Scripting

how to extract a certain part of a line

Hi friends, I want to select and use the certain part of a line. For example I have the following line home/1245/hgdf/acsdf/myhome/afolder/H2O/endfile how can I extract the part " /myhome/afolder/H2O/endfile " thanks (6 Replies)
Discussion started by: rpf
6 Replies

7. Shell Programming and Scripting

How to extract one part from whole output

Hi All, I am trying to write a small shell programming to get db2 database size info. The command I am going to use is- db2 "CALL GET_DBSIZE_INFO(?, ?, ?, -1)" and the output of above command generally is- Value of output parameters -------------------------- Parameter Name :... (4 Replies)
Discussion started by: NARESH1302
4 Replies

8. Shell Programming and Scripting

extract last part of string.

Hi, I have a string like this BUNDLE=/home/bob/flx/user.bun how to extract only the the last part ie, only user.bun (2 Replies)
Discussion started by: vprasads
2 Replies

9. UNIX for Dummies Questions & Answers

extract a part of a path like (input: /etc/exp/home/bin ====> output: exp)

Hi, I need to make some extraction . with the following input to get the right output. input: /etc/exp/home/bin ====> output: exp and input: aex1234 ===> output: ex Thanks for your help, (4 Replies)
Discussion started by: yeclota
4 Replies

10. UNIX for Dummies Questions & Answers

Extract a part of file name

Hi, I want to extract a part of filename and pass it as a parameter to one of the scripts. Could someone help. File name:- NLL_NAM_XXXXX.XXXXXXX_1_1.txt. Here i have to extract only XXXXX.XXXXXXX and the position will be constant. that means that i have to extract some n characters from... (6 Replies)
Discussion started by: dnat
6 Replies
Login or Register to Ask a Question