Problem in getting data from a loop using grep and cut

The script is following :

for each_rec in <file_name>
do
  count=`cut -c -2 ${each_rec} | grep "45"`
  echo ${count}
  if [[ ${count} -eq 45 ]] then
    amount=`cut -c 24-35 ${each_rec}`
    echo ${amount}
  else
    echo "failed"
  fi
done

And the file looks like below :

01000007683+0000013071+001449750.71+001596774.86 2010-09-27201009
02000000219+0000001463+000188697.81+000187069.70 2010-09-27201009
03000000652+0000003367+000212138.84+000847244.61 2010-09-27201009
04000001175+0000005397+000126543.77+000460763.26 2010-09-27201009
05000001890+0000012514+000059183.61+000038238.85 2010-09-27201009
06000000254+0000001149+000004773.04+000000251.77 2010-09-27201009
07000000128+0000000590+000002843.56+000000148.39 2010-09-27201009
08000002728+0000008947+008282517.52+004450313.95 2010-09-27201009
12000000917+0000001974+000555783.18+000819727.45 2010-09-27201009
14000000007+0000000010+000004773.00+000001026.80 2010-09-27201009
15000000298+0000016858+000334163.89+000478644.01 2010-09-27201009
16000000000+0000000000+000000000.00+000000000.00 2010-09-27201009
18000000000+0000000000+000000000.00+000000000.00 2010-09-27201009
27000000078+0000000196+000009205.21+000003151.24 2010-09-27201009
21000000057+0000000219+000039995.49+000039382.41 2010-09-27201009
25000000000+0000000000+000000000.00+000000000.00 2010-09-27201009
30000000116+0000000466+000299833.16+000005895.46 2010-09-27201009
40000002108+0000003477+000311888.91+000219808.01 2010-09-27201009
35000000010+0000000281+000033884.00+000032151.00 2010-09-27201009
28000000336+0000001258+000799387.65+000313825.85 2010-09-27201009
60000000690+0000003421+001010850.57+000564147.45 2010-09-27201009
55000000000+0000000000+000000000.00+000000000.00 2010-09-27201009
51000000615+0000002544+000010538.52+000000597.82 2010-09-27201009
52000000436+0000002738+000010654.19+000000673.83 2010-09-27201009
53000000084+0000000455+000004983.83+000000323.46 2010-09-27201009
09000002856+0000074490+001429055.86+002321155.60 2010-09-27201009
10000000332+0000001322+000006250.50+000000328.37 2010-09-27201009
11000000041+0000000176+000000968.00+000000112.64 2010-09-27201009
45000000010+0000000033+000011481.00+000008827.54 2010-09-27201009

Expected result :

000011481.00

Result coming as :

001449750.71
000188697.81
000212138.84
000126543.77
000059183.61
000004773.04
000002843.56
008282517.52
000555783.18
000004773.00
000334163.89
000000000.00
000000000.00
000009205.21
000039995.49
000000000.00
000299833.16
000311888.91
000033884.00
000799387.65
001010850.57
000000000.00
000010538.52
000010654.19
000004983.83
001429055.86
000006250.50
000000968.00
000011481.00

I am trying to fetch the corresponding column, where the first two field matches with 45. But, every time the cut is fetching the whole column.
Please help me on this .

$ ruby -F'\+' -ane 'puts $F[2] if $F[0][0,2]=="45"' file
000011481.00

#!/bin/ksh
for each_rec in `cat <filename>`
do
count=`echo ${each_rec}|cut -c -2 | grep "45"`
echo ${count}
if [[ "${count}" = "45" ]]; then
amount=`echo ${each_rec}|cut -c 24-35`
echo ${amount}
else
echo "failed"
fi
done

The quick way:

grep \^"45" filename | cut -f3 -d+
000011481.00

Alternatively modifying your script to use a "while" not a "for" loop. There is never a reason to use a "for" loop with an open-ended list.
Also corrected various syntax anomalies. Note that "cut" either takes input from a pipeline or a file (in this case we need to use "echo" to get the record onto a pipeline).

cat filename | while read each_rec
do
  count=`echo "${each_rec}" | cut -c1-2`
  if [ ${count} -eq 45 ]
  then
       amount=`echo "${each_rec}" | cut -c24-35`
       echo "${amount}"
  fi
done
000011481.00
awk -F + '/^45/ {print $3}' infile

000011481.00

---------- Post updated at 10:25 AM ---------- Previous update was at 10:24 AM ----------

var=45

awk -F + '/^'"$var"'/ {print $3}' infile