Sponsored Content
Full Discussion: Tnanames.ora parser
Top Forums Shell Programming and Scripting Tnanames.ora parser Post 302962400 by Don Cragun on Monday 14th of December 2015 04:47:26 AM
Old 12-14-2015
With the sample input you provided, the following script seems to do what you want:
Code:
#!/bin/ksh
awk '
!/^[[:space:]]/ {
	NAME = $1
	next
}
/[(]ADDRESS / {
	hos = index($0, "HOST = ") + 7
	pos = (hoe = index($0, ")(PORT = ")) + 9
	ADDRESS_PORT = ADDRESS_PORT "    " substr($0, hos, hoe - hos) "," \
	    (substr($0, pos) + 0)
#print
#printf("hos=%d,hoe=%d,pos=%d,ADDRESS_PORT=\"%s\"\n",hos,hoe,pos,ADDRESS_PORT)
	next
}
/[(]SERVICE_NAME / {
	snos = index($0, " = ") + 3
	snoe = index($0, ")")
	printf("%s    %s%s\n", NAME, substr($0, snos, snoe - snos), ADDRESS_PORT)
#print
#printf("snos=%d,snoe=%d,SERVICE_NAME=\"%s\"\n",snos,snoe,substr($0,snos,snoe-snos))
	ADDRESS_PORT = ""
}' file

although I am assuming that you had a typo in the output you said you wanted....

The above script produces the output:
Code:
PRI    pri    10.0.3.7,1521    10.0.3.17,1521
STDBY    stdby    10.0.3.5,1521    10.0.3.15,1521    10.0.3.25,1521
AIXSNAP    aixsnap    10.9.0.5,1521

while the output you said you wanted was:
Code:
PRI    pri    10.0.3.7,1521    10.0.3.17,1521
STDBY    stubby    10.0.3.5,1521    10.0.3.15,1521    10.0.3.25.1521
AIXSNAP    aixsnap    10.9.0.5,1521

If you can't see how the index() and substr() functions are working to extract the data you want, you can uncomment the commented out print and printf() statements to see values being used.

If someone wants to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

path of init.ora

hi i would like to know the path of init.ora in AIX Server i tried with find command but i could not find it. can somebody help me with that. (8 Replies)
Discussion started by: matrixmadhan
8 Replies

2. Solaris

init.ora

what is the function of the init.ora file and suppose by mistake it gets deleted , what will be the consequences on the server (1 Reply)
Discussion started by: asalman.qazi
1 Replies

3. Solaris

maxuprc and maxusers - ORA-27300, ORA-27301, ORA-27302

Hi all, Am intermittently getting the following errors on one of my databases. Errors in file /oracle/HRD/saptrace/background/hrd_psp0_13943.trc: ORA-27300: OS system dependent operation:fork failed with status: 12 ORA-27301: OS failure message: Not enough space ORA-27302:... (1 Reply)
Discussion started by: newbie_01
1 Replies

4. UNIX for Advanced & Expert Users

grep all ORA errors except one ORA error

Hi - I am trying to grep all "ORA" errors in a log files.I have to grep all ORA errors except one error for example ORA-01653.How can exclude that error in "grep" command? In following "grep" command I want to exclude "ORA-01653" error grep -i ORA alert.log >>/tmp/ora_errors.txt ... (7 Replies)
Discussion started by: Mansoor8810
7 Replies

5. HP-UX

ORA-27300 error because of hp ux

Dear All, i am not able to start the 9i oracle database because of the following problems. I log in into unix and then into sqlplus export oracle_sid=SATEST startup nomount i am getting the following errors ORA-27300: OS system dependent operation:semget failed with... (3 Replies)
Discussion started by: alokpattar
3 Replies

6. Shell Programming and Scripting

editing init.ora

Hi all- i am having some hiccups while writing a korn shell to edit init.ora file for automating latest PSU patchset.(Oracle) I am trying to edit(add) the ._fix_control and .event with certain parameters. if anyone has any idea that will be helpful. thanks. (1 Reply)
Discussion started by: sub
1 Replies

7. Shell Programming and Scripting

Tnsnames.ora

Hi, I would like to modify, in script schell, the line right above (DESCRIPTION and check three cases : if line contain ".world" then line=line-".world" concat "," concat line if line dont contain ".world" then line=line concat "," concat line concat".world" else line=line Keep in... (10 Replies)
Discussion started by: elcaro
10 Replies

8. Shell Programming and Scripting

Check for “errors” or “ORA-”

I want to check for "errors" or "ORA-" in Y.if there is an error then exit Y=`sqlplus -s user/passwd<< EOF exec test_Proc; exit; EOF` if ; then exit 1 fi but this doesnt work (6 Replies)
Discussion started by: haadiya
6 Replies

9. Shell Programming and Scripting

Parsing Listener.ora

Anymore have any code to easily parse the listener.ora to update the ORACLE_HOME for a specific sid? thanks. (1 Reply)
Discussion started by: nugent
1 Replies

10. Red Hat

Ora-27603:ora-27626:

Hi, User claim that job is running slow from their end. I DBA found in database the below errors in alert log file. ORA-27603: Cell storage I/O error, I/O failed on disk o/192.168.10.3/RECO_DM01_CD_01_drm01 at offset 13335789568 for data length 1048576 ORA-27626: Exadata error: 2201 (IO... (2 Replies)
Discussion started by: Maddy123
2 Replies
XML_SET_OBJECT(3)							 1							 XML_SET_OBJECT(3)

xml_set_object - Use XML Parser within an object

SYNOPSIS
bool xml_set_object (resource $parser, object &$object) DESCRIPTION
This function allows to use $parser inside $object. All callback functions could be set with xml_set_element_handler(3) etc and assumed to be methods of $object. PARAMETERS
o $parser - A reference to the XML parser to use inside the object. o $object - The object where to use the XML parser. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 xml_set_object(3) example <?php class xml { var $parser; function xml() { $this->parser = xml_parser_create(); xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, "tag_open", "tag_close"); xml_set_character_data_handler($this->parser, "cdata"); } function parse($data) { xml_parse($this->parser, $data); } function tag_open($parser, $tag, $attributes) { var_dump($parser, $tag, $attributes); } function cdata($parser, $cdata) { var_dump($parser, $cdata); } function tag_close($parser, $tag) { var_dump($parser, $tag); } } // end of class xml $xml_parser = new xml(); $xml_parser->parse("<A ID='hallo'>PHP</A>"); ?> PHP Documentation Group XML_SET_OBJECT(3)
All times are GMT -4. The time now is 11:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy