Replace with shell variable in awk

Hi,

Probably this is a out of scope of the thread. I have a requirement as below

I have a file with below content

CMD //DS > testfile

I have to replace

//DS

with a value which is assigned to a variable outside using awk gsub.
For example

var=TEST

I expect an output as

CMD TEST

I tried below 2 awk

awk '{gsub(/\/\/DS/,$var);print}' testfile

this fails

awk '{gsub(/\/\/DS/,"$var");print}' testfile

This doesn't replace the var value.

Could you please help me ?

---------- Post updated at 11:52 AM ---------- Previous update was at 11:31 AM ----------

I could accomplish this using sed as below

sed 's/\/\/DS/,'$var'/g' filename

Still looking for awk

Thanks

Try:

awk -v var="$var" '{gsub(/\/\/DS/,var);print}' testfile

--
Note: The reason your awk attempt did not work is that the single quotes preventes the shell variables from being expanded..