Facing issues with shell script changes

My current requirement is to replace xxyxx string with value of date

date1 variable holds a date

and the current script writes html tags to a file as follows

 echo date1
  nawk 'BEGIN{
  FS=","
  print "<HTML>""<HEAD>""<p>Hi All,<br><br>There are no cases closed on the xxyxx"
  print  "that meet the criteria for submission.</p>"
  }
  END{
  print "<p>Regards,<br>Application Team</p></BODY></HTML>"
  }
  ' /u001/Scripts/abc.txt > /u001/Scripts/abc.html

I have tried like this as follows,

gawk -i inplace 'NR==1{gsub(/xxyxx/,"$$date1")};1' /u001/Scripts/abc.html 

I am getting search string replaced as $$date1 instead I want value of date1

and the following sed command is not working

sed -i 's/xyxx/'"$date1"'/' /u001/Scripts/abc.html

Basically never use options like -i as they have lots of unfortunate side effects, like changing file ownerships and permissions besides destroying your original input if anything goes wrong. It's not worth it just to make a pretty one-liner.

awk 'NR==1 { sub(OLD, NEW); }; 1' OLD="xxyxx" NEW="XXYXX" inputfile > outputfile
# Uncomment these once you've tested awk does what you want.
# cat outputfile > inputfile
# rm -f outputfile

A few further comments:

  • As you don't use any awk feature in your sample code, why use it at all? A shell "here document" might be way more efficient leading to the same result.
  • IF you insist on awk , why run it twice in lieu of putting it all into one script?
  • Look into awk 's man page to find out about how to pass variables / parameters into it.
  • The $$ will lead you nowhere in awk , and yield the process ID in (most) shells.
  • Your output will be missing the </HEAD> closing tag, and the <BODY> opening one.