How to replace variable inside the variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to replace variable inside the variable
# 22  
Old 03-22-2007
Add set -vx and show the trace.
Did you add this to your script sed "s/;/;\\
/g"
Code:
set -vx

USERID=USER/pass
SCRIPTFILE=/rnmucdr/ednms05/ken/xMNBDF045_Script.sql
BILLDATE=19-FEB-07
STARTPARTNNUM=101
TOTALPARTN=20
SQLLOG=${BILLDATE}_xMNBDF045_P_CTEL.log

sed 's/\([()\*]\)/\\\1/g' $SCRIPTFILE > tmp
mv tmp $SCRIPTFILE

echo $SQLLOG
echo $SCRIPTFILE
SCRIPT=$( eval echo $(cat ff) | sed "s/;/;\\
/g")

sqlplus -s $USERID > $SQLLOG << EOF
WHENEVER SQLERROR EXIT 1
$SCRIPT
EOF

if [ $? -ne 0 ]
then
cat $SQLLOG
else
echo "SUCCESSFULLY FINISHED" > $SQLLOG
fi

# 23  
Old 03-22-2007
bro thanks bro,
its works find,
acuatly i put the /g same line after i put in new line it works
thanks man
but i not much understand the sed commands,i new in it
will learn soon with your help
thanks man
# 24  
Old 03-22-2007
hi bro need your help again,
this path /rnmucdr/ednms05/ken/template/xMNBDF070_Script.sql
Code:
set echo off;
set head off;
set feedback off;
set pagesize 0;
spool $OUTPUTFILENAME;
select to_char(bill_date,'yyyymmdd')||rpad(acct_no,14)||withhold_code||to_char(withhold_qty,'fm009') from invoice where sys_a
ppl_id = '$SYSAPPLID' and bill_date = '$BILLDATE' and withhold_code is not null and withhold_qty > 0;
spool off;
exit;

since this have pipe | is there so i added pipe as bellow

Code:
USERID=user/pass
SYSAPPLID=NTEL
BILLDATE=01-JAN-07
OUTPUTFILENAME=/rnmucdr/ednms05/ken/data/${SYSAPPLID}_${BILLDATE}_WITHHOLD_ACCTS.dat
LOGFILENAME=/rnmucdr/ednms05/ken/logs/${SYSAPPLID}_${BILLDATE}_xMNBDF070_P_CTEL.log
SCRIPTFILE=/rnmucdr/ednms05/ken/template/xMNBDF070_Script.sql
TEMPWRITEFILE=/rnmucdr/ednms05/ken/xMNBDF070_Script.sql.TMP

sed -e "s/'/\\\'/g" -e 's/\([();*|]\)/\\\1/g' $SCRIPTFILE > $TEMPWRITEFILE

SCRIPTFILE=$TEMPWRITEFILE


SCRIPT=$( eval echo $(cat $SCRIPTFILE) | sed "s/;/;\\
/g")


sqlplus -s $USERID 1> $OUTPUTFILENAME 2>$LOGFILENAME<< EOF
WHENEVER SQLERROR EXIT 1
$SCRIPT
EOF

if [ $? -ne 0 ]
then
cat $OUTPUTFILENAME > $LOGFILENAME
rm $OUTPUTFILENAME > /dev/null
cat $LOGFILENAME
else
echo "SUCCESSFULLY CREATE FILE $OUTPUTFILENAME" > $LOGFILENAME
fi

But it doesnt work???
Any other problem
sorry to trouble you again and again
# 25  
Old 03-22-2007
Add >
Code:
sed -e "s/'/\\\'/g" -e 's/\([();*|>]\)/\\\1/g' $SCRIPTFILE > $TEMPWRITEFILE

# 26  
Old 03-22-2007
thanks man it works,i am so dump...
# 27  
Old 03-23-2007
Code:
DB=abcserv
DB_USERID=ad
DB_PASSWORD=devfl
SYSAPPLID=NTEL
DP_FILE_SYS_ID=Cas
BILLDATEF1=010107
BILLDATEF2=01/01/07
OUTPUTFILENAME=/rnmucdr/ednms05/withold_accts/config/FNBDPCF2_${SYSAPPLID}
LOGFILENAME=/rnmucdr/ednms05/withold_accts/logs/${SYSAPPLID}_${BILLDATE}_xFNBDPCF2_${SYSAPPLID}.log
SCRIPTFILE=/rnmucdr/ednms05/withold_accts/template/FNBDPCF2
TEMPWRITEFILE=/rnmucdr/ednms05/withold_accts/FNBDPCF2_${SYSAPPLID}.TMP

sed -e "s/'/\\\'/g" -e 's/\([();*|>]\)/\\\1/g' $SCRIPTFILE > $TEMPWRITEFILE

SCRIPTFILE=$TEMPWRITEFILE

eval echo $(cat $SCRIPTFILE) | sed "s/;/;\\
/g" > test

if [ $? -ne 0 ]
then
cat $OUTPUTFILENAME > $LOGFILENAME
rm $OUTPUTFILENAME > /dev/null
cat $LOGFILENAME
else
echo "SUCCESSFULLY CREATE FILE $OUTPUTFILENAME" > $LOGFILENAME
fi

rm $TEMPWRITEFILE > /dev/null

This file rnmucdr/ednms05/withold_accts/template/FNBDPCF2 content

Code:
[files]
LBTNRR01=./bt/FNBBTBACT.dp;
LDP03R01=/nbfprod01/work/${SYSAPPLID}/dp/FNBDPFMT;
LDP01W01=/nbfprod01/work/${SYSAPPLID}/dp/TESTFILE;
LDF0TR01=/nbfprod01/work/${SYSAPPLID}/dp/FNBDPFMT_TRN;
LDF0AR01=/nbfprod01/work/${SYSAPPLID}/dp/FNBDPFMT_ADR;
LDF0MR01=/nbfprod01/work/${SYSAPPLID}/dp/FNBDPFMT_MSG;
LDP0RW01=/nbfprod01/work/${SYSAPPLID}/dp/FNBDPINF;
LDP0RR01=/nbfprod01/work/${SYSAPPLID}/dp/FNBDPINF;
LDP0CW01=/nbfprod01/work/${SYSAPPLID}/dp/FNBCYRPT;

[databases]
D0001=$DB,$DB_USERID,$DB_PASSWORD,,ORACLE;
D0000=$DB,$DB_USERID,$DB_PASSWORD,,ORACLE;
D0003=$DB,$DB_USERID,$DB_PASSWORD,,ORACLE;

[environment]

[parameters]
LDPTEMP2=/nbfprod01/work/${SYSAPPLID}/dp/TEMP2;
LDPTEMP3=/nbfprod01/work/${SYSAPPLID}/dp/TEMP3;
NORMALBILLFILENAME=/nbfprod01/work/${SYSAPPLID}/dp/${DP_FILE_SYS_ID}bp${BILLDATEF1}.kod10;
ERRORBILLFILENAME=/nbfprod01/work/${SYSAPPLID}/dp/${DP_FILE_SYS_ID}bp${BILLDATEF1}.kod20;
MANDIVBILLFILENAME=/nbfprod01/work/${SYSAPPLID}/dp/${DP_FILE_SYS_ID}bp${BILLDATEF1}.kod30;
FOREIGNBILLFILENAME=/nbfprod01/work/${SYSAPPLID}/dp/${DP_FILE_SYS_ID}bp${BILLDATEF1}.kod40;
FINALBILLFILENAME=/nbfprod01/work/${SYSAPPLID}/dp/${DP_FILE_SYS_ID}bp${BILLDATEF1}.kod50;
FINALCRAMTFILENAME=/nbfprod01/work/${SYSAPPLID}/dp/${DP_FILE_SYS_ID}bp${BILLDATEF1}.kod80;
HIGHBILLFILENAME=/nbfprod01/work/${SYSAPPLID}/dp/${DP_FILE_SYS_ID}bp${BILLDATEF1}.HIGH;
BINSFILENAME=/nbfprod01/work/${SYSAPPLID}/dp/BINS_FILE;
EXCEPTIONFILENAME=/nbfprod01/work/${SYSAPPLID}/dp/EXCEP_BILL;
NOPRINTFILENAME=/nbfprod01/work/${SYSAPPLID}/dp/${DP_FILE_SYS_ID}bp${BILLDATEF1}.kod70;
FR52_FINALBILLFILENAME=/nbfprod01/work/${SYSAPPLID}/dp/${DP_FILE_SYS_ID}bp${BILLDATEF1}.kod52;
FIN31BILLFILENAME=/nbfprod01/work/${SYSAPPLID}/dp/${DP_FILE_SYS_ID}bp${BILLDATEF1}.kod31;
FR82_FINALBILLFILENAME=/nbfprod01/work/${SYSAPPLID}/dp/${DP_FILE_SYS_ID}bp${BILLDATEF1}.kod82;
HIGHBILLFILENAME21=/nbfprod01/work/${SYSAPPLID}/dp/${DP_FILE_SYS_ID}bp${BILLDATEF1}.kod21;
SYSDIVBILLFILENAME=/nbfprod01/work/${SYSAPPLID}/dp/${DP_FILE_SYS_ID}bp${BILLDATEF1}.kod90;
HIGHAMOUNT=250000;
BINPAGELIMIT=10000;
REPLACESTRING=+++++;
START_FPGMSG_LINE=16;
START_FPGMSG_POSN=68;
MSGLINEWIDTH=23;
MSGLINELENGTH=30;
LEAVESPACE=YES;
SKIP_IND_FIELD=bfi;
SKIP_IND_VALUE=MSGBFIFP;
SAVING_BFI=XX_PKJSM;
SAVING_MSG=Tahniah! Anda telah mendapat penjimatan sebanyak;
SAVING_FMT=999,999,999.00;
SAVING_TYPE=M;
PRICING_MSG= ;
PG_BRK_POS=1;
OMR_POS=2;
OMR_DEF=-;
OMR_LEN=1;
NIPSON_POS=3;
NIPSON_LEN=2;
LINE_LEN=90;
LINE_IN_PAGE=79;
SECHDR_DEF=SH;
SECFTR_DEF=SF;
HDR_DEF=H;
DTL_DEF=D;
COLHDR_DEF=CH;
NUMBER_POS=74;
SMALLCASE_BILLMONTH_ACCTCAT="T,C,I";
ACCT_CAT=T;
MODULE_ID=DP;
TOT_INST=1;
PCCB_IND_BFI=ADR01;
CUR_CHRG_BFI=BFICC001;
DUE_AMT_BFI=BFIDU001;
TXNRECTYPE=OTR;
DPSORTCOMD=./configs/dp_sorter_T.pbm;
RESI_ERRBILLAMOUNT=5000;
BUSI_ERRBILLAMOUNT=250000;
BILL_DATE=$BILLDATEF2;
CYBERPRINT_REPORT=N;

How to write this to file name test

i want replace all the variables, the i want the file as it is,i dunt want the [database] and [parameters] join in one sentences
can u help me,i want go to new line after found new line but now it go to new line after found ;
can you help me thanks
[/code]
# 28  
Old 03-23-2007
Code:
DB=abcserv
DB_USERID=ad
DB_PASSWORD=devfl
SYSAPPLID=NTEL
DP_FILE_SYS_ID=Cas
BILLDATEF1=010107
BILLDATEF2=01/01/07
sed -e "s/\${SYSAPPLID}/${SYSAPPLID}/" -e "s/\${BILLDATEF1}/${BILLDATEF1}/" rnmucdr/ednms05/withold_accts/template/FNBDPCF2 >test

Similarly use substitute command for other variables. Make sure that all the variables in input file is enclosed in braces
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 replace a parameter(variable) date value inside a text files daily with current date?

Hello All, we what we call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to... (1 Reply)
Discussion started by: pradeepp
1 Replies

2. Shell Programming and Scripting

To print value for a $variable inside a $variable or file

Hi guys, I have a file "abc.dat" in below format: FILE_PATH||||$F_PATH TABLE_LIST||||a|b|c SYST_NM||||${SRC_SYST} Now I am trying to read the above file and want to print the value for above dollar variables F_PATH and SRC_SYST. The problem is it's reading the dollar variables as... (5 Replies)
Discussion started by: abcabc1103
5 Replies

3. Red Hat

How to pass value of pwd as variable in SED to replace variable in a script file

Hi all, Hereby wish to have your advise for below: Main concept is I intend to get current directory of my script file. This script file will be copied to /etc/init.d. A string in this copy will be replaced with current directory value. Below is original script file: ... (6 Replies)
Discussion started by: cielle
6 Replies

4. Shell Programming and Scripting

evaluating a variable inside a variable

Hi there, i think im getting myself a little confused and need some help :wall: I am reading in a bunch of variables to my script from an external file and need to validate that a value has been set for each so if you can imagine, the user is required to pass in 4 values... (3 Replies)
Discussion started by: rethink
3 Replies

5. Shell Programming and Scripting

Not able to store command inside a shell variable, and run the variable

Hi, I am trying to do the following thing var='date' $var Above command substitutes date for and in turn runs the date command and i am getting the todays date value. I am trying to do the same thing as following, but facing some problems, unique_host_pro="sed -e ' /#/d'... (3 Replies)
Discussion started by: gvinayagam
3 Replies

6. Shell Programming and Scripting

variable inside variable inside loop headache

Hi Gurus I have a file called /tmp/CMDB which looks like this serial: 0623AN1208 hostname: server1 model: x4100 assetID: 1234 I am writing a for loop that will go through this file line by line creating a variable of itself. Using the first iteration of the loop (i.e. the first line) as... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

7. Shell Programming and Scripting

passing a variable inside another variable.

Any help would be great. I know this is a dumb way of doing this, but I would like to know if there is a solution doing it this way. I'm very new at this and I'd like to learn more. Thanks! :D:D count=0 while ; do echo "enter your name" read name_$count let count=count+1 done ... (2 Replies)
Discussion started by: reconflux
2 Replies

8. Shell Programming and Scripting

Sed , Replace a "variable text" inside of a statement

Please Help... I am trying to manipulte the following line Before : <user:Account_Password>002786</user:Account_Password> the password is the "variable", i need to delete / omit the password in the file, (it occurs several thousand times) so the tag line looks like After:... (4 Replies)
Discussion started by: jackn7
4 Replies

9. UNIX for Dummies Questions & Answers

passing a variable inside a variable to a function

I would like to know how to pass a variable inside a variable to a function. sample code below -------------- for x in 1 9 do check_null $C$x ##call function to check if the value is null if then echo "line number:$var_cnt,... (2 Replies)
Discussion started by: KingVikram
2 Replies

10. Shell Programming and Scripting

ksh: A part of variable A's name is inside of variable B, how to update A?

This is what I tried: vara=${varb}_count (( vara += 1 )) Thanks for help (4 Replies)
Discussion started by: pa3be
4 Replies
Login or Register to Ask a Question