A summing issue

Hi All,

Here is the problem:

The input file is like as per below. Each record has 30 chars in total. Have to add the first 17 and the next 13 and append the output. Total records can vary.

000000004728800000000000003908
000000003005100000000000002484
000000002602200000000000002151
000000003418400000000000002825
000000001059900000000000000876
000000001146200000000000000947
000000000973700000000000000805
000000001561300000000000001290
000000001088600000000000000900
000000001146200000000000000947
000000001029300000000000000851
000000001034500000000000000855
000000000977700000000000000808
000000000888800000000000000735
000000000884200000000000000731
000000001061100000000000000877
000000002721600000000000002249
000000001040800000000000000860
000000001353100000000000001118
000000001306300000000000001080
000000001088600000000000000900
000000001000400000000000000827
000000001034500000000000000855
000000018798400000000000015536
000000005204400000000000004301
000000002292400000000000001895
000000002865600000000000002368
000000000973700000000000000805
000000001002200000000000000828

Please advise.

Ashu

You aren't doing homework, are you?

man bash

look for ${var:n:n}

Try awk

awk '{print $0(substr($0,1,17)+substr($0,18,13))}' data.file

Danmero,

Thanks for your rpeloy but it doesn't seem to work.
Can you please look into it.

Thanks.

#!/usr/bin/ksh
for line in `cat sample`
do
first17=`echo $line | cut -c1-17`
next13=`echo $line | cut -c18-30`
sum=$(($first17 + $next13))
echo $sum
done

Namish,

Thansk for your reponse but I want the follwoing.

file.txt

111111111111111112000000000000
111111111111111112000000000000
111111111111111112000000000000
111111111111111112000000000000

output should be

444444444444444448000000000000

Sorry for any confusion.

Thanks
Ashu