sed command to replace one value which occurs multiple times

Hi,

My Input File :

 "MN.1.2.1.2.14.1.1" := 
"MN_13_TM_4" ( 000000110110100100110001111110110110101110101001100111110100011010110111001 )
"MOS.1.2.1.2.13.6.2" := 
 "MOS_13_TM_4" ( 000000110110100100110001111110110110101110101001100111110100011010110111001 ) 
 

Like above template,I have multiple entries of MN and MOS.
I want to replace only "MOS_13_TM_4" value in the input file without touching "MN_13_TM_4" value,although both values are same i.e

000000110110100100110001111110110110101110101001100111110100011010110111001

using following command will replace the value at both places(MN & MOS)

i.e. sed 's/000000110110100100110001111110110110101110101001100111110100011010110111001/00000011011010010011000111111011011010111010100110011111010001101011011MMMM

How to replace only MOS value?

sed 's/\(MOS_13_TM_4.*\)000000110110100100110001111110110110101110101001100111110100011010110111001/\100000011011010010011000111111011011010111010100110011111010001101011011MMMM/' file

Try:

sed '/MOS_13_TM_4/s/\(00000011011010010011000111111011011010111010100110011111010001101011011\)1001/\1MMMM/' file

or

sed '/MOS_13_TM_4/s/\(\([01]\)\{71\}\)[01]\{4\}/\1MMMM/' file

or

sed '/MOS_13_TM_4/s/[01]\{4\} )$/MMMM )/' file

@balajesuri

if I defined following variables -

set x=MOS_13_TM_4
set value=000000110110100100110001111110110110101110101001100111110100011010110111001
set tmp=100000011011010010011000111111011011010111010100110011111010001101011011MMMM

Can you correct the following command ? :

	sed -i	's/\('$x'.*\)'$value'/\'$tmp'/' file

You could change it to:

	sed -i	's/\('$x'.*\)'$value'/\1'$tmp'/' file

and it will work with your sample data, but

	sed -i	"s/\($x.*\)$value/\1$tmp/" file

is MUCH easier to read and will still work if either or both of your search pattern and replacement string contain spaces and/or tabs.