Double grep and replacing

Hi All,

I need to replace a match with are new values when there is a double match.

grep 04422494 MAX.dat | grep 1102300131 

I need to replace 1102300131 as 1101600131 in MAX.dat only for the record matching 04422494 . I tried replace as

sed/s/1102300131 /1101600131 /g MAX.dat 

but it replace all records including 04422494 and other records.

Can you please help

Thanks
Arun

having a sample input and desired output would help....

Below is the example

sample input

000442249411023001312016031500000000000000001872000000000000000
000442249411023001312016032100000000000000001872000000000000000
000442249411023001312016032100000000000000001872000000000000000
000442249411023001312016033100000000000000001872000000000000000
000442249511023001312016031500000000000000001872000000000000000
000442249511023001312016032100000000000000001872000000000000000
000442249611023001312016032100000000000000001872000000000000000
000442249611023001312016033100000000000000001872000000000000000

desired output

000442249411016001312016031500000000000000001872000000000000000
000442249411016001312016032100000000000000001872000000000000000
000442249411016001312016032100000000000000001872000000000000000
000442249411016001312016033100000000000000001872000000000000000
000442249511023001312016031500000000000000001872000000000000000
000442249511023001312016032100000000000000001872000000000000000
000442249611023001312016032100000000000000001872000000000000000
000442249611023001312016033100000000000000001872000000000000000

Try:

sed 's/^\(0004422494\)1102300131/\11101600131/' file

or, a less accurate but maybe good enough:

sed '/04422494/s/1102300131/1101600131/' file
1 Like