AnotherAlan
Technical User
Hi All,
I'm having the usual nightmare trying to get a sed command to accept variables in a substitution; It works on the command line and I can see that the shell has interpolated the variable correctly by using echo, but when I run it in the script it just doesn't update.
File: Pre SED
IT412 587XX 7
IT412 627P5 7
IT412 133D4 39.5
From command line;
sed 's/IT412 587XX 7/IT412 587XX '"$V587XX"'/' testfile > testfile1
cat testfile1;
IT412 587XX 721.00
IT412 627P5 7
IT412 133D4 39.5
echo from script;
sed 's/IT412 587XX 7/IT412 587XX '721.84'/'
Run via script;
Totalswifts=`awk '(NR>1){sum +=$3}END{print sum - 53.5}' $SWIFTFTP/$FILENAME.txt`
V587XX=`expr $Totalswifts*0.07 | bc`
V627P5=`expr $Totalswifts*0.07 | bc`
V133D4=`expr $Totalswifts*0.395 | bc`
sed 's/IT412 587XX 7/IT412 587XX '"$V587XX"'/' $SWIFTFTP/$FILENAME.txt > /tmp/testfile1
OUTPUT;
cat testfile1
IT412 587XX 7
IT412 627P5 7
IT412 133D4 39.5
This is probably a simple quoting issue, but I can't see it at the moment.
All help appreciated.
Thanks
Alan
I'm having the usual nightmare trying to get a sed command to accept variables in a substitution; It works on the command line and I can see that the shell has interpolated the variable correctly by using echo, but when I run it in the script it just doesn't update.
File: Pre SED
IT412 587XX 7
IT412 627P5 7
IT412 133D4 39.5
From command line;
sed 's/IT412 587XX 7/IT412 587XX '"$V587XX"'/' testfile > testfile1
cat testfile1;
IT412 587XX 721.00
IT412 627P5 7
IT412 133D4 39.5
echo from script;
sed 's/IT412 587XX 7/IT412 587XX '721.84'/'
Run via script;
Totalswifts=`awk '(NR>1){sum +=$3}END{print sum - 53.5}' $SWIFTFTP/$FILENAME.txt`
V587XX=`expr $Totalswifts*0.07 | bc`
V627P5=`expr $Totalswifts*0.07 | bc`
V133D4=`expr $Totalswifts*0.395 | bc`
sed 's/IT412 587XX 7/IT412 587XX '"$V587XX"'/' $SWIFTFTP/$FILENAME.txt > /tmp/testfile1
OUTPUT;
cat testfile1
IT412 587XX 7
IT412 627P5 7
IT412 133D4 39.5
This is probably a simple quoting issue, but I can't see it at the moment.
All help appreciated.
Thanks
Alan