replace strings in a file

Hi

I want to change the following

passwd: files nis
group: files nis

in /etc/nsswitch.conf

to be

passwd: files compat
group: files compat

I tried

cp -p nsswitch.conf nsswitch.conf.old

sed -e 's:passwd\: files nis:passwd\: files compat:g' -e 's:group\: files nis:group\: files compat:g' nsswitch.conf.old > nsswitch.conf

It only changes passwd not group:

passwd: files compat
group: files nis

could you please advise?

thank you

sed 's/nis/compat/' filename

hi

but there are other occurences of 'nis' string while I want to change only 2 occurences.

thx

I tried this

cp -p nsswitch.conf nsswitch.conf.old
sed -e '/<passwd>/!s/passwd\(.\)/passwd\: files compat/' \
-e '/<shadow>/!s/shadow\(.
\)/shadow\: files compat/' \
-e '/<group>/!s/group\(.*\)/group\: files compat/' \
nsswitch.conf

but this changes also

netgroup: files nis

to

netgroup: files compat