To trim Certain field in a line of a file and replace the new string in that position

To trim 3rd field in for all the lines of a file and replace the modified string in that particular field.

For example i have a file called Temp.txt having content
Temp.txt
-----------------
100,234,M1234
400,234,K1734
300,345,T3456
----------------

So the modified file output should be
Temp.txt
-----------------
100,234,1234
400,234,1734
300,345,3456
----------------

Soplution: I did like this

while read line
do
VAR=`echo $line | cut -f3 -d ','` ( VAR=M1234)
VAR1=`echo $VAR | cut -c2-` (VAR1=1234)
???????????????????????????
??????????????????????????

done < Temp.txt

So please help me how i will replace VAR1 inplace of VAR and got the output as i specified above..

Thanks in advance...

Hi.

You can use Awk:

awk -v FS="," -v OFS="," '{$3 = substr($3, 2)} 1' Test.txt

If you are freak of sed this will do..

sed 's/\(.*\),\(.*\),[aA-zZ]\(.*\)/\1,\2,\3/g' filename

Shorter:

sed 's/[a-zA-Z]//g' file

And shell version

#!/bin/ksh
# or bash
while IFS="," read f1 f2 f3 fx
do
       new3=${f3:1}
       echo "$f1,$f2,$new3"
done <  Temp.txt