Hi All,
I have a file abc.txt with 3 fileds. Field 3 contains amount. Also at the end of file there is a Footer record, which contains total amount.
I need to calculate total sum of these fields & need to compare it with footer record. I have serched in thi site, many has asked this questions, but i am not able to find out solution.
File
AM8906~JHUT56~100
AM5640~RESWD~200
Checksum~ 300
I need to get sum (100+200) & then to compare it with Checksum. Can someone help me on this
awk -F'~' '{ if($1!="Checksum") s+=$3
else if(s==$2) print "Sum Matched with Footer"
else print "Sum is not Matching with Footer"
}' abc.txt
if you are finding an EXACT solution to your problem, then i can say you will not find it. However similar ones, you can.
awk -F"~" '!/Checksum/{total+=$NF}/Checksum/{ print total==$NF ? "ok" :"not ok"}' file
line=`cat filename | wc -l`
nawk -v l="$line" -F"~" '{
if(NR<l)
p=p+$3
else
c=$2
}
END{
if(p>c)
print "Sum of parts is larger than the checksum"
else if (p<c)
print "Sum of parts is less than the checksum"
else
print "Match"
}' filename
Hi all,
there is a little bit changes... i am cutting the amount field from the source file and putting into one file.... called amount_1
amount_1
00000000000000006247.5
0000000000000000001071
0000000000000000003590
00000000000000001229.5
0000000000000000000400
0000000000000000785.77
0000000000000000012472
0000000000000000374.98
0000000000000000001550
what i need is to get the sum of this number & store it into a variable.
Then i will cut the total_amount from source file & store it in a variable. Then i will compare these 2 variable to decide future actions...
i have tried to do R&D from above 2 diff codes, but not able to do so... can you please help me
Hi All,
I have worked on almost all solution got from google. but none of this is working.
1
sum=0
for i in 1 2 3 4 5 6
do
echo $i
((sum=sum+i))
done
echo "Summed up value is $sum"
-
for i in `list whatever column you want`
do
sum=$(echo "$sum + $i"|bc)
done
echo "Summed up value is $sum"
can someone please help me
# eval $(awk '{a+=$0}END{printf "%s=%.5f\n","var", a}' amount_1)
# echo $var
27720.75000
Thank you Danmero.. now this is working...
great help.....