I referred posts:
Sed command : how to replace if exists else just insert?
But none of the solution seems to be working. Can anybody explain why?
I am just executing the commands on the terminal by making that particular file
sed -e 's/^avpgw/new text/' -e t -e 's/^av/new text/' -e t -e 's/^/new text/' file
sed '/^FOOBAR=/{h;s/=.*/=newvalue/};${x;/^$/{s//FOOBAR=newvalue/;H};x}' infile