Find and replace a string a specific value in specific location in AIX

Hi,

I have following samp.txt file in unix.

samp.txt

01Roy2D3M000000
02Rad2D3M222222
.
.
.
.
10Mik0A2M343443

Desired Output

01Roy2A3M000000
02Rad2A3M222222
.
.
.
.
10Mik0A2M343443

I want to find a value for 2D3M in the 6,7,8,9 positions from the beginning of record, if found need to replace it with 2A3M

Thanks

sed "s/^\(.\{5\}\)2D3M/\12A3M/" file

Hi anbu23,

Thanks for quick reply..so this will check for the string only in the 6, 7, 8, 9 positions only right..and it should not check any other positions of every records of the file..

sed "s/^\(.\{5\}\)2D3M/\12A3M/" file

what does 1 mean before 2A3M in the above SED command.

Pls respond..thanks..

sed code will check 2A3M only from 6th to 9th position in the file.

\(.\{5\}\) Holds first five characters. \1 gives the first five characters saved in \( \)

gr8..thanks/...it worked..)

Sed is better in this case, here is the awk code.

awk -F "" '{if (substr($0,6,4)=="2D3M") $7="A"}1' OFS="" samp.txt