Cut two individual position and summ

Hi All,

I am having a huge file file. I need to cut the below column and do the below calculation

I did the below command and able to do on full databased no on the individual based any help on doing each row by row

cut -c 52-56  myfile | awk '{total = total + $1}END{print total}'
cut -c 59-62  myfile | awk '{total = total + $1}END{print total}'

Thanks,
Arun

A sample (~6 lines) input would be helpful...

You want row-by-row sums of the last two rows?

What does your data look like, anyway? You could bundle this up all in one awk if I knew.

cut -c 52-56  myfile | awk '{ if(L) print L+$1 ; L=$1 }'

On top of what vgersh99 said, why do you deploy two cut and two awk commands, when all can be done in one single awk only?

Yes . Basically I want to

(52-56  -  59-62)  * 100

on all individual row in the file

Sample Data

043166251511150314847023310369200085508025354741201002440000000006247447OZ000000001200000100000060CS08014N0000 
079417671505150127847024800058510000008025354921201003850000000006262303OZ000000001200000100000050OO08002N0000
083771661512150315847000000058510000008025354921201003000000000006262303OZ000000001200000100000050OO19032N0000
085905871508150218847000000085510000008025354841301003290000000006288735OZ000000001200000100000050OO20018N0000
304442121513150326847000000058550000008025354921201003450000000006262303OZ000000001200000100000050OO19035M0000

Thanks
Arun

awk '{print (substr($0,52,5) - substr($0,59,4)) / 100}' <yourfile>
1 Like

Yes, good - but shouldn't either substr 's length be increased by one?

1 Like

you are correct so I edited it.