LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   sed help with variable (http://www.linuxquestions.org/questions/programming-9/sed-help-with-variable-653478/)

RudraB 07-04-2008 12:01 AM

sed help with variable
 
i have a script:

Quote:

for (( i=1;i<=9;i++ ))
do
j=`expr 10 - $i`
mkdirhier Dir/Mn${i}Cr${j}
cp FFILES/param.h Dir/Mn${i}Cr${j}
rho=`echo "scale=1; $i/10" | bc`
echo $rho
sed -e '6c\ parameter(nsite=369902,x=${i},y=1-x,nkp=17,maxrec=12)' Dir/Mn1Cr9/param.h>tmp$i
cp tmp$i Dir/Mn1Cr9/param.h
done
the problem is with sed line....i expect sed to replace x=${i}, where i is variable; but sed is just prompting ${i}; not the current value of $i:cry: ...any help?

Kenhelm 07-04-2008 01:10 AM

${i} needs to be out of the single quotes. Try something like this:-
Code:

'........before......'"${i}"'.....after.....'
so that ${i} is now in double quotes while the rest of the sed statement remains in single quotes.


All times are GMT -5. The time now is 08:00 AM.