Modify a file by another file: add new line and variable after string is found

hello,

I have problem with writing/adjusting a shell script.
I searched forum and unfortunately couldn't write scipt based on the information I found.
I never wtire such so it's hard for me and I do need to modify one script immediately.

case looks like:

  1. 'file' that needs to be modified
  2. 'script' - it has commands in order to modify a 'file'

'script' has to modify 'file' according to the rule:
Each time when a 'string' is found inside a 'file' then a new line should be added with variable and its value.
example:
'file' has:

something, something
something string more
something, something
hello world, string

'script' should serach for 'string' and each time when it find it then a new line with variable $$var1=5 should be added.
after modification 'file' should look like:

something, something
something string more
$$var1=5
something, something
hello world, string
$$var1=5

can someone tell me how to do this?

thanks a lot!

What shell is this?

What have you tried?

Hi, do you something mean like this?

awk '/string/{ $0=$0 RS v }1' v='$$var1=5' infile

Why the double $-signs and should it be always the same variable?

code:

while read line
do
count=`echo $line | grep 'string' | wc -l `
if [ $count = 1 ]
then
        echo $line
        echo '$$var1=5'
else
        echo $line
fi
done < infile.txt > temp
rm infile.txt
mv temp infile.txt