Updating variables using sed or awk

Hi,
I have a file(testfile.txt) that contains list of variables as shown below. T

$$FirstName=James
$$LastName=Fox
$$Dateofbirth=1980-02-04

��and so on there are 50 different variables.

I am writing a script(script1.sh) that will update the above three variable one by one with the values passed as a parameter to the script.

So Script1.sh Ron Donnely 1960-01-31 passing the three parameters.

Scripts1.sh take these three parameter in $1, $2 and $3.

I am trying to see if there is a SED or AWK that I can use in Script1.sh to update the testfile.txt to update the variable values with the values passed to the script as a parameter. So the values in testfile.txt should look like something below:

$$FirstName=Ron
$$LastName=Fox
$$Dateofbirth=1960-01-31

Please note: Variable Filename cannot be changed.

Will appreciate any help.
Thanks

Perhaps something like this:

#!/bin/sh

# Setting IFS="%" causes "${*}" to become "arg1%arg2%arg3%arg4".
OLDIFS="$IFS" ; IFS="%"

# arg1%arg2%arg3%arg4 gets split in awk later to A[1]=arg1, A[2]=arg2, A[3]=arg3, A[4]=arg4.
# Line 1 matches A[1] gets arg1, line 2 matches A[2] gets arg2, etc.
awk -F= -v OFS="=" -v S="${*}" 'BEGIN { split(S,A,"%") } ; NR in A { $2=A[NR] } 1' filename > newfilename

Hello Saanvi,

Following may help you in same too but here considering the values will not have spaces in themselves.

 cat test78.ksh
for j in $@
do
        let "i = i + 1"
        VAL1=`head -$i test78`
        VAL=`echo ${VAL1%%=*}`
        echo $VAL"="$j
done
 

Output will be as follows.

./test78.ksh test singh 1960-01-31
$$FirstName=test
$$FirstName=singh
$$FirstName=1960-01-31
 

Thanks,
R. Singh

Thanks Corona for the response. Will the above fix will work if the variable are not one below the other. I am sorry if it was not clear in my post. The file contains more than 50 variables. I want to update few of them based on the variable name and assign them new values.
I just gave an example in my post that happened to be one below the other. The update of the variable value needs to happen based on the variable name that I choose in my script. It can be $$POBOX variable on 45 line.The point is the variables, I am trying to update are not below one below the other. One variable can be on line 10 the other one on 40. Hence looking to update the variable value by picking up the variable name and assigning new value to it.

---------- Post updated at 02:47 PM ---------- Previous update was at 02:45 PM ----------

Thank you R Singh. Let me try your suggested code.

Thanks again

The arguments don't contain any variable names at all. How should the script decide what names to update?

If the list of names and order of arguments is fixed:

#!/bin/sh

NAMES='$$FirstName $$LastName $$Dateofbirth'

IFS="%"

awk -F= -v OFS="=" -v VS="${NAMES}" -v S="${*}" 'BEGIN { split(S,A,"%") ; split(VS,VY," ") ; for(X in VY) V[VY[X]]=A[X] } $1 in V { $2=V[$1] } 1' < inputfile > outputfile

The latter "script1.sh" deserves an example/instruction:

 cat inputfile
#comment
$$notthis
$$FirstName=James
$$LastName=Fox
$$Dateofbirth=1980-02-04
 ./script1.sh "Ron%Donnely%1960-01-31"
 cat outputfile
#comment
$$notthis
$$FirstName=Ron
$$LastName=Donnely
$$Dateofbirth=1960-01-31