Link to home
Start Free TrialLog in
Avatar of bibi92
bibi92Flag for France

asked on

question about awk

Hello,

I have a file in variable $Dbprp which content :


hostname1_1511_db1.world
hostname2_1512_db2.world
hostname3_1513_db3.world
hostname4_1514_db4.world
hostname5_1515_db5.world

For each line, I search to get three following variables
host = hostname1
port = 1511
base = db1

I try this, but the result for base is hostname1_1511_db1.world. How can I resolve?

for db in `cat $Dbprp`
do
       
        [ ! $db ] && db="error listener.ora" # pb get db on listener.ora files
        echo $db

        host=`echo $db | awk -F'_' '{ print $1 }'`
      port=`echo $db | awk -F'_' '{ print $2 }'`
        base=`echo $db | awk -F'_' '{ print $3 }'| sed 's/.world//g'`

done

Thanks

Regards
Avatar of ozo
ozo
Flag of United States of America image

That is not the result I get.
How did you determine that the result for base is hostname1_1511_db1.world?
Avatar of bibi92

ASKER

Hello,

With this command :
echo "insert into test values (''' || $host || '''' || ',' || '''' || $port || '''' || ',' || '''' || $base|| '''' ||',null,trunc(sysdate));" >> $WorkFile

Thanks
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bibi92

ASKER

Sorry but we haven't the same result and for the simple loop :
IFS+=_.:  not found

Thanks
What do you get in $WorkFile?
Which shell are you using?
Avatar of bibi92

ASKER

I've requested that this question be deleted for the following reason:

I have found a solution with delete || in insert statement thanks regards
What is the solution with delete || in insert statement?
What do you get in $WorkFile?
Which shell are you using?
Avatar of bibi92

ASKER

You are right. I have forgotten I changed the output for insert in Oracle db. Thanks regards