Awk parameter substitution not working

This is one looong running thread with confusing posts from the OP.
your original script:

grep NVARCHAR2 test2 | awk '{print substr($4,12)}' > Nvarcharfields
for i in `cat Nvarcharfields`
do
echo $i
awk '{if (substr($2,13)=="\"$i\"")  {$10="ChangeX"} print $0}' test2 > test6
done

How about this withOUT the loop and all the extra hops you wanted to go with:

#/bin/bash
awk '
FNR==NR {if (/NVARCHAR2/) f1[substr($4,12)];next}
substr($2,13) in f1 {$10="ChangedX"}
1
' test2 test2 > test6

Not tested. Just simplifying the steps, and I don't know WHAT is behind these steps/logic and/or what's the bigger picture you're trying to achieve, but it should get you started with the better skeleton.
It could also help YOU/us, if you could provide a small representative sample of test2.
BTW, PLEASE start using markdown code tags when posting code/data samples - I believe you've been asked/warned before.

1 Like