variable substitution in sed
This is a simple stuff yet i couldn't solve it myself.
The issue goes as below,
i need to place fprintf after every pattern matched in a C code.
eg: if a c code has
then a printf should be placed after the line as below
fprintf (stderr,"Accessing alloc id %x", ALLOCID_2x0023);
there are list of files to be modified whose list is there in the "file_list". the pattern to be searched are there in "alloc_ids".
i wrote a code,
while read line
while read line1
grep $line $line1
if [ $? -eq 0 ]
##echo " The $line in file $line1"
fprintf(stderr,"Acccesing alloc id %x",$line);' < $line1 > $line1.swp
The problem is, i'm not able to do variable substitution for the variable "$line" which has the pattern.
If i put quotes instead of single quote for the sed, it throws an error "cannot parse ...bla..bla.."
On the whole , it just writes the entire fprintf line as a string in the new file inclusive of $line being written as such without any substitution.
Any help would be appreciated..please