Need to get word after a specific word


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to get word after a specific word
# 8  
Old 03-21-2016
Hi,

This is not working as expected.I am looking for hostname from tnsping output.

Code:
c456veq {/home/oracle}: tnsping ora426b |sed -n 's/\(.*HOST=\)\([^)]*\)\(.*\)/\2/p'
c456veq {/home/oracle}: tnsping ora426b

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 21-MAR-2016 11:13:05

Copyright (c) 1997, 2013, Oracle.  All rights reserved.

Used parameter files:
/u01/app/oracle/product/11.2.0.4/db/network/admin/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = c299njy.int.thomsonreuters.com)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = ora426b.int.thomsonreuters.com)))
OK (0 msec)


Best regards,
Vishal
# 9  
Old 03-21-2016
The = is surrounded by spaces that you need to capture
Code:
sed -n 's/\(.*HOST *= *\)\([^)]*\)\(.*\)/\2/p'

You can omit the non-needed brackets
Code:
sed -n 's/.*HOST *= *\([^)]*\).*/\1/p'

This User Gave Thanks to MadeInGermany For This Post:
# 10  
Old 03-22-2016
Thanks!

Since this is manual entry in tnsnames.ora file so somewhere this would be like

Code:
HOST=
HOST = 
host =
host=

Can we get all these possibilities covered in the script ?

Best regards,
Vishal
# 11  
Old 03-22-2016
A straight-forward conversion of MadeInGermany's script to use case insensitive matches would be:
Code:
sed -n 's/.*[Hh][Oo][Ss][Tt] *= *\([^)]*\).*/\1/p'

Some versions of sed have an option to perform case insensitive matches, but the above should work with any version of sed.
This User Gave Thanks to Don Cragun For This Post:
# 12  
Old 03-22-2016
Thanks Sir!

Best regards,
Vishal
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to search for a word in column header that fully matches the word not partially in awk?

I have a multicolumn text file with header in the first row like this The headers are stored in an array called . which contains I want to search for each elements of this array from that multicolumn text file. And I am using this awk approach for ii in ${hdr} do gawk -vcol="$ii" -F... (1 Reply)
Discussion started by: Atta
1 Replies

2. Shell Programming and Scripting

Search for a specific word and print only the word from the input file

Hi, I have a sample file as shown below, I am looking for sed or any command which prints the complete word only from the input file. Ex: $ cat "sample.log" I am searching for a word which is present in this file We can do a pattern search using grep but I need to cut only the word which... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

3. Shell Programming and Scripting

How to print multiple specific column after a specific word?

Hello.... Pls help me (and sorry my english) :) So I have a file (test.txt) with 1 long line.... for example: isgc jsfh udgf osff 8462 error iwzr 653 idchisfb isfbisfb sihfjfeb isfhsi gcz eifh How to print after the "error" word the 2nd 4th 5th and 7th word?? output well be: 653 isfbisfb... (2 Replies)
Discussion started by: marvinandco
2 Replies

4. Shell Programming and Scripting

Need a word which just comes next to after grep of a specific word

Hi, Below is an example : ST1 PREF: int1 AVAIL: int2 ST2 PREF :int1 AVAIL: int2 I need int1 to come in preferred variable while programming and int2 in available variable Please help me doing so Best regards, Vishal (10 Replies)
Discussion started by: Vishal_dba
10 Replies

5. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

6. Shell Programming and Scripting

Fetch entries in front of specific word till next word

Hi all I have following file which I have to edit for research purpose file:///tmp/moz-screenshot.png body, div, table, thead, tbody, tfoot, tr, th, td, p { font-family: "Liberation Sans"; font-size: x-small; } Drug: KRP-104 QD Drug: Placebo Drug: Metformin|Drug:... (15 Replies)
Discussion started by: Priyanka Chopra
15 Replies

7. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

8. UNIX for Dummies Questions & Answers

How to print line starts with specific word and contains specific word using sed?

Hi, I have gone through may posts and dint find exact solution for my requirement. I have file which consists below data and same file have lot of other data. <MAPPING DESCRIPTION ='' ISVALID ='YES' NAME='m_TASK_UPDATE' OBJECTVERSION ='1'> <MAPPING DESCRIPTION ='' ISVALID ='NO'... (11 Replies)
Discussion started by: tmalik79
11 Replies

9. Shell Programming and Scripting

Grep out specific word and only that word

ok, so this is proving to be kind of difficult even though it should not be. say for instance I want to grep out ONLY the word fkafal from the below output, how do I do it? echo ajfjf fjfjf iafjga fkafal foeref afoafahfia | grep -w "fkafal" If i run the above command, i get back all the... (4 Replies)
Discussion started by: SkySmart
4 Replies

10. Shell Programming and Scripting

How to replace a specific word in specific column?

Hi My orginal file is like (100s of lines) id host ip location remarks 1 host1 ip1 - xxx 2 host2 ip2 - xxx 3 host3 ip3 - xxx -- -- 9 host9 ip9 - xxx I have a ref file like host1 location1 host2 location2 host3 location3 -- --... (6 Replies)
Discussion started by: ./hari.sh
6 Replies
Login or Register to Ask a Question