Extract a column and multiple by 1000 and replace it on same file

Hi All,

I need to extract a position in the file and multiple the value by 1000 and the replace it .

Original
0010001200084701217637306521200000000000010010000000  ---> 000847 * 1000
0010012700086001213437404323000000000000001001000000 ---> 000860 * 1000
0010018100092001217641402424000000000000000000000000 --> 000920 * 1000
0010030705571601222242405524000000000000000000000001 --> 055716 * 1000

Expected :
0010001284700001217637306521200000000000010010000000  ---> 000847 * 1000
0010012786000001213437404323000000000000001001000000 ---> 000860 * 1000
0010018192000001217641402424000000000000000000000000 --> 000920 * 1000
0010030705571601222242405524000000000000000000000001 --> 055716 * 1000

The problem is if I 055716 with 1000 will get 55716000 .Since my layout can handle only 6 digit I should be able to store 557160 . I am not able to fit this into. I am able to extract separate with awk but not able to fit in the file. Also I am not to convert the 55716000 this scenario in aw

Hello arunkumar_mca,

Could you please try following once.

awk '{val1=substr($0,9,6);val2=val1+0<10000?sprintf("%06d",val1*1000):val1;print substr($0,1,8) val2 substr($0,15)}'  Input_file

Thanks,
R. Singh

1 Like

Try also

awk '
    {print substr($0,1,8) substr (sprintf ("%d", substr($0, 9, 6) "000"), 1, 6) substr($0,15)
    }
' file
1 Like