help with printf command

hello,

I'm trying to display Unix variable using printf command.

Code:

 
awk '{ if ( $0 ~ /string/ ) {
printf( "%s\n%s\n",$0,"dsd"); #this one works
printf( "%s\n%s\n",$0,$HOME); #this does not work
} else {
print $0;
}
}' param1_1.txt 

I could use here echo command but I'm not sure how to use it properly.

I mean "properly" because the intention of this code is to serach for a particular string in a code and then when the string is found then a specific variable should be displaied in the next line after the string.

with simple text I can achieve this but not with variable.
Does anyone know how to correct this?

You're trying to access a shell variable from awk. You need to pass these to awk with -v "awkvar=$shellvar"

so your example would be:

awk -v "home=$HOME" '
{
  if ( $0 ~ /string/ ) {
    printf( "%s\n%s\n",$0,"dsd"); #this one works
    printf( "%s\n%s\n",$0,home); #this should now work
  } else {
    print $0;
  }
}' param1_1.txt

Is this homework?