Shell parameter substitution does not take place in data files.
You will need to process the line in Shell if you want Shell to perform the substitution.
For example:
There are other alternatives, such as:
1) Read the environment variables with the SQL progam. I don't know how to do this in your SQL but most database languages offer this.
2) Use sed or ed to change the SQL.txt file.
3) Use a SQL program to change the SQL.txt file.
actually i dont want to use my SQL with in the shell....coz my SQL may contains more than 500 lines....so i want to store it in a file and need to run...moreover i dont want to edit the shell(editing SQL in shell) each time when Requirement changes....rather i can change the SQL stored in a file
The reason is that the parsing process in the shell runs in steps: in one steps all the parameters are expanded, in one step all the files are being read, etc. This is why you can have a "here-document" containing variables (which will be expanded to there values), but not a file containing variables.
You have several options, but probably the easiest one to maintain is: you could parse (this is: replace the variables with their content) your file ( /home/karthik/SQL.txt, if I'm correct) yourself prior to reading it. If you have a file with variable definitions (i called it "some_declaration_file") of the form
You could do the following:
Actually the "sed"-statement changes "${variable}" to "content_of_variable" if in the declaration file there is a line
Instead of reading this declaration file completely line by line (as i have done with the while-loop) you could also limit your replacement to several lines of this declaration file.
even i could not understand your points too as im very new to unix ..
please correct me ..
---------- Post updated at 09:05 AM ---------- Previous update was at 09:01 AM ----------
let me tell what i understood...
1. need to copy the content of SQL.txt into another file ...
2. there i need to replace the parameter content with original value
3. need to use it that for futher SQL processing
---------- Post updated at 12:11 PM ---------- Previous update was at 09:05 AM ----------
thanks sir ....its working fine ....i tried something with ur code(combination urs + my understanding) ..its working fine
I have file called in in.txt contains with the below lines I want to display the lines between the value which I would be passing.
one
two
three
four
five
ten
six
seven
eight
Expected output if I have passed one and ten
two
three
four
five (8 Replies)
I have a below syntax its working fine...
var12=$(ps -ef | grep apache | awk '{print $2,$4}')
Im getting expected output as below:
printf "%b\n" "${VAR12}"
dell 123
dell 456
dell 457
Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
I have a small program which needs to pass variable dynamically to form the name of a second variable whose value wil be passed on to a third variable.
***************** Program Start ******************
LOC1=/loc1
PAT1IN=/loc2
PAT2IN=/loc3
if ; then
for fpattern in `cat... (5 Replies)
Hi Folks,
I would like to pass a variable with a wild card in an argument. My script works if I don't use a wildcard but fails when I use *. I want to use the script like:
scriptname -F <filename*>
@ i = 0
while ($i <= ${#argv})
switch ($argv)
case -F:
set j = `echo $i +1... (2 Replies)
hi,
i am trying to call a unix script in a c program, this unix script will set a flag, the value of which i would like to return to the calling C program. this is the code that i have written.. the get env functions works if i use other env variables set at session level in unix like... (1 Reply)
Dear All,
I want to print a file.
First I tried with this
sed '2q;d' filename
it worked. But when i put following it is not working
x=2;
sed '$xq;d' filename
Would any one suggest how to pass the variable? (7 Replies)
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)
Hi, I'm a bit of sed n00b here.
My issue is as follows:
I'm trying to pass a variable to sed so that all instances of this variable (in a text file) will be replaced with nothing. However, the value of this variable will always be a folder location e.g. "C:\Program Files\Folder1"
I... (5 Replies)
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)
Hi,
If a script A(Parent) is running and script B(child) is run from script A, will the variables in script A be past to script B?
Will the variables exist only for the duration of running the script?
Thank you (2 Replies)