Read section of file and take decision

Hi,

My requirement is that I've to read a config file having below info

 
Oracle
number|double;integer  -> user can put multiple values here
blob|binary
varchar2|string
varchar|string
number(p,s)|decimal
timestamp|date/time
and so on ....
 
Sybase
bigint|bigint
datetime|date/time
money|decimal
smallint|small integer
and so on ....
 

In the script I take a XML file as an input and extracts the source database and source & target tables' field's datatype info as below:

What I want to achieve is that

 
if $src_database = "Oracle" ;then
          read only Oracle section of the config file
   if $src_datatype = "number"; then 
          get the right hand side value i.e. "double" & "integer" and check if 
          either of the value matches with the $tgt_datatype then
          echo "matches"
   else
          echo "doesn't match"
   fi
fi

Please advice. Thanks.

-dips

Please post sample of XML file and desired o/p.

Hi Pravin,

Actually from the XML file I am able to extract values for below variables:

$src_database=Oracle
$src_datatype=number
$tgt_datatype=double

What I want now is to check if number = double is fine?
This translation I can read from config file only. Hope I'm clear now. Sorry for the confusion my initial post created.

-dips

---------- Post updated 2011-04-15 at 12:15 PM ---------- Previous update was 2011-04-14 at 02:23 PM ----------

Hi,

I'm able to read a section of file by changing the format of the file a little

Changed config file:

 
$cat temp.cfg
landing_dir=XXXX
scripts_dir=XXXX
....
 
<Oracle>
number|double;integer  
blob|binary
varchar2|string
varchar|string
number(p,s)|decimal
timestamp|date/time
<Oracle>
 
<Sybase>
bigint|bigint
datetime|date/time
money|decimal
smallint|small integer
....
<Sybase>

To read only "Oracle" section from the file (searched forum)

 
awk '/\<Oracle\>/{p=0}p;/\<Oracle\>/{p=1}' temp.cfg

In my script I'll have variables holding source & target datatypes as below:

$src_datatype=number
$tgt_datatype=double

Scenario 1
Now as $src_datatype variable is "number" then I want to read only

 
number|double;integer  

this line from the temp.cfg

and check whether $tgt_datatype is either of them i.e. "double" or "interger"?

Scenario 2
If $src_datatype variable is "number(p,s)" then I want to read only

 
number(p,s)|decimal

this line from temp.cfg

and check whether $tgt_datatype is "decimal" ?

I tried

 
awk '/\<Oracle\>/{p=0}p;/\<Oracle\>/{p=1}' temp.cfg | grep -w "$src_datatype"

but it selects two lines

 
number|double;integer
number(p,s)|decimal

Please advice on how to proceed further. Thanks for your time.

-dips