awk gsub with variables?

Hey,

I would like to replace a string by a new one. Teh problem is that both strings should be variables to be flexible, because I am having a lot of files (with the same structure, but in different folders)

for i in daysim_*
do
    cd $i/5/
    folder=`pwd |awk '{print $1}'`
    awk '{ if (NR==14) {gsub($2, $folder); print} }' ill_5_06.hea
    cd ../..
done

But of course it doesn't work. So the problem is how to deal with the variable $folder in gsub?

Thanks for any suggestions, Sam.

IMO double post of:

Thread closed.

awk '{ if (NR==14) {gsub($2, f); print} }' f="${folder}" ill_5_06.hea

BTW, I think your 'gsub()' is either incomplete and/or incorrect:

     gsub(ere,repl[,in])
           Behave like sub  (see  below),  except  that  it  will
           replace  all  occurrences  of  the  regular expression
           (like the ed utility global substitute) in  $0  or  in
           the in argument, when specified.

Hmm, yeah, but it doesn't work.

it works, if I am using the gsub like this:

But it doesn't work if the second one is replace by a variable, too.
Maybe the problem could be solved if the content of $folder is not

folder=/bla/bla/

then

folder="/bla/bla/"

But how to tell awk that ' " ' isn't the beginning of a string? (folder=`pwd |awk '{print $1}'`). Because /" also doesn't work...

Thanks