add or modify if existent

I want to set these params in /etc/system

set shmsys:shminfo_shmmax=2000000000
set shmseg:shminfo_shmseg=200

if this param exists, then I want to modify them
if not, I want to add them.

I can add them using >>/etc/system
but how to do the modify thing?
at least I can comment the existing lines -if existent- and then add the 2 entries.

sed -e "s/.*shmsys:shminfo_shmmax.*/set shmsys:shminfo_shmmax=2000000000/" -e "s/.*shmseg:shminfo_shmseg.*/set shmseg:shminfo_shmseg=200/" /etc/system > tmp
mv tmp /etc/system 

thanks. this is modiying but not adding in case the entry does not exist.
can you please advise?

awk -F"[ =]" '
BEGIN { arr["shmsys:shminfo_shmmax"]="set shmsys:shminfo_shmmax= 2000000000";
arr["shmseg:shminfo_shmseg"]="set shmseg:shminfo_shmseg=200"; }
{ if( arr[$2] !~ /^ *$/ ) { print arr[$2]; delete arr[$2]; }
  else print }
END {
for( key in arr ) {
	if( arr[key] !~ /^ *$/ ) { print arr[key] }
} } ' /etc/system > tmp
mv tmp /etc/system
cat<<! >tmp && mv tmp /etc/system
$(egrep -v "^set (shmsys:shminfo_shmmax|shmseg:shminfo_shmseg)" /etc/system)
$(printf "set shmsys:%s\nset shmseg:%s\n" "shminfo_shmmax=2000000000" "shminfo_shmseg=200")
!