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
# 15  
Old 03-21-2007
try this
Code:
sed -e "s/'/\\\'/g" -e 's/\([();*]\)/\\\1/g' $SCRIPTFILE > tmp
mv tmp $SCRIPTFILE

I am able to see all the sql statements.
# 16  
Old 03-21-2007
I have tested this code and i working:

USERID=XXXXXX
SQLLOG=sqllog
SCRIPT=`cat sql`
value=`sqlplus -silent $USERID > $SQLLOG <<END
WHENEVER SQLERROR EXIT 1
$SCRIPT
END`
if [ $? -ne 0 ]
then
cat $SQLLOG
else
echo "SUCCESSFULLY FINISHED" > $SQLLOG
fi
# 17  
Old 03-21-2007
It says invalid semicolon
i need somecommand to enter after each line
if i type in straight it works but now it reads at one line
Here is the error
Code:
create table acct_to_print_bak as select BILL_DATE,ACCT_NO,STATUS_CODE,floor((ROWNUM-1)/N)+101 BP_PARTN_NUM,SYS_APPL_ID FROM ( select T1.BILL_DATE,T1.ACCT_NO,T1.STATUS_CODE,T1.BP_PARTN_NUM,T1.SYS_APPL_ID,T3.N from acct_to_print t1,inv_acct_bill_addr T2 ,(select ceil(count(*)/20) N from inv_acct_bill_addr) T3 where t2.bill_date='19-FEB-07' and t2.bill_date=t1.bill_date and t1.ACCT_NO=t2.ACCT_NO order by T2.postal_code ) T4; commit; truncate table acct_to_print; insert into acct_to_print (select * from acct_to_print_bak); commit; drop table acct_to_print_bak
                                                                                                                                                                                                                                                                                                                                                                                                                                         *
ERROR at line 1:
ORA-00911: invalid character

# 18  
Old 03-21-2007
Now try with cat command:

Code:
USERID=XXXXXX
SQLLOG=sqllog
SCRIPT=`cat sql`
value=`sqlplus -silent $USERID > $SQLLOG <<END
WHENEVER SQLERROR EXIT 1
cat sql
END`
if [ $? -ne 0 ]
then
cat $SQLLOG
else
echo "SUCCESSFULLY FINISHED" > $SQLLOG
fi

# 19  
Old 03-21-2007
Hi sir,i think the problem will solve if the variable keeps with new line,now it displays as one sentence for this
Code:
SCRIPT=$( eval echo $(cat $SCRIPTFILE))

and output
all in one sentences

if after each semi colon followed by newline then problem solve
expected output like this
Code:
create table acct_to_print_bak as
select BILL_DATE,ACCT_NO,STATUS_CODE,floor((ROWNUM-1)/N)+$STARTPARTNNUM BP_PARTN_NUM,SYS_APPL_ID FROM (
select T1.BILL_DATE,T1.ACCT_NO,T1.STATUS_CODE,T1.BP_PARTN_NUM,T1.SYS_APPL_ID,T3.N from acct_to_print t1,inv_acct_bill_addr T2
,(select ceil(count(*)/$TOTALPARTN) N from inv_acct_bill_addr) T3 where t2.bill_date='$BILLDATE' and t2.bill_date=t1.bill_dat
e and t1.ACCT_NO=t2.ACCT_NO order by T2.postal_code ) T4;
commit;
truncate table acct_to_print;
insert into acct_to_print (select * from acct_to_print_bak);
commit;
drop table acct_to_print_bak;

if you use your code all will join as one sentences and the
Code:
select * from acct_to_print_bak

The * for above code will replace with all file names tht exist the the path for example like
Code:
select abc.txt fileA.cpp from acct_to_print_bak

other * work fine maybe its because printed in one line
plz help me
# 20  
Old 03-22-2007
Code:
$ x=$( eval echo $(cat file))
$ echo $x
create table acct_to_print_bak as select BILL_DATE,ACCT_NO,STATUS_CODE,floor((ROWNUM-1)/N)+101 BP_PARTN_NUM,SYS_APPL_ID FROM ( select T1.BILL_DATE,T1.ACCT_NO,T1.STATUS_CODE,T1.BP_PARTN_NUM,T1.SYS_APPL_ID,T3.N from acct_to_print t1,inv_acct_bill_addr T2 ,(select ceil(count(*)/20) N from inv_acct_bill_addr) T3 where t2.bill_date='19-FEB-07' and t2.bill_date=t1.bill_dat e and t1.ACCT_NO=t2.ACCT_NO order by T2.postal_code ) T4; commit; truncate table acct_to_print; insert into acct_to_print (select 01.xxxx 01.xxxx.Z 02.xxx.Z 90, a anbu b f f.s f.st f1 f1.s f2 ff ff.st file newfile oldfile s temp tmp from acct_to_print_bak); commit; drop table acct_to_print_bak;
$ echo "$x"
create table acct_to_print_bak as select BILL_DATE,ACCT_NO,STATUS_CODE,floor((ROWNUM-1)/N)+101 BP_PARTN_NUM,SYS_APPL_ID FROM ( select T1.BILL_DATE,T1.ACCT_NO,T1.STATUS_CODE,T1.BP_PARTN_NUM,T1.SYS_APPL_ID,T3.N from acct_to_print t1,inv_acct_bill_addr T2 ,(select ceil(count(*)/20) N from inv_acct_bill_addr) T3 where t2.bill_date='19-FEB-07' and t2.bill_date=t1.bill_dat e and t1.ACCT_NO=t2.ACCT_NO order by T2.postal_code ) T4; commit; truncate table acct_to_print; insert into acct_to_print (select * from acct_to_print_bak); commit; drop table acct_to_print_bak;

If you use quotes around the variable then it wont expand to all the files in that directory. But you dont need to worry about that. This expansion wont occur when you send variable to sqlplus.

To add newline after each semicolon
Code:
SCRIPT=$( eval echo $(cat ff) | sed "s/;/;\\
/g")

# 21  
Old 03-22-2007
still it doesnt work

Code:
create table acct_to_print_bak as select BILL_DATE,ACCT_NO,STATUS_CODE,floor((ROWNUM-1)/N)+101 BP_PARTN_NUM,SYS_APPL_ID FROM ( select T1.BILL_DATE,T1.ACCT_NO,T1.STATUS_CODE,T1.BP_PARTN_NUM,T1.SYS_APPL_ID,T3.N from acct_to_print t1,inv_acct_bill_addr T2 ,(select ceil(count(*)/20) N from inv_acct_bill_addr) T3 where t2.bill_date='19-FEB-07' and t2.bill_date=t1.bill_date and t1.ACCT_NO=t2.ACCT_NO order by T2.postal_code ) T4;  commit;  truncate table acct_to_print;  insert into acct_to_print (select * from acct_to_print_bak);  commit;  drop table acct_to_print_bak
                                                                                                                                                                                                                                                                                                                                                                                                                                         *
ERROR at line 1:
ORA-00911: invalid character

The error show for semicolon,
its still not go to new line afteruse the command you give,any suggestion
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