puzzling me now way to long....so hopefully someone has the answer at hand:
The following shows a sample tnsnames.ora from another topic.
What I want to get as result the tnsnames alias "PRI" when searching for the service name pri.
That is, the left hand side of the tnsnames entry where the service name 'pri' is used.
Preferably shell script or sed.
thanks again for giving me the time to find out what to correct...I now run
awk '
$2 != "=" { next }
$1 == "(SERVICE_NAME" && $3 ~ s { print a }
$1 !~ /^\(/ { a=$1 }
' s="pri" tnsnames.ora
...and it matches just fine. How do I make it case insensitive? Can you please explain how it works?
I think the first line skips over the tnsnames.ora until it finds a pattern 'variable ='. So this will give us the left hand side in $1?
The second line searches for the SERVICE_NAME entry, where the value matches s, which is set on the command line to be 'pri'.
You store this in $1 ....but didn't we keep the left hand side there?
I forgot that ( is special in ERE, that awk uses. You found it: needs to be escaped. An alternative would be [(] .
Each code line is a condition { action } .
All three code lines are run for each input line.
If the condition in the 2nd code line is true it performs the action: print variable a .
This is set in the 3rd code line to field#1, if it does not have a ( at the beginning.