I have a script that goes through a 24 hr logfile, And i want to count the instances of a Test01 to 83 and output the sum of all the instances over 24hrs
#/bin/ksh
cat $parse_data | awk '/'$time$i'/ {for(x=0; x<=16; x++) {getline; print}print "--" }' > _hr.txt
for y in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 81 82 83 84 85
do
tot_alarms=`cat _hr.txt | grep -c "Network=Test$y"`
Sample$y= `expr $Sample$y + $tot_alarms `
echo " The no of alarms for this is $Sample$y"
done
done
The output is as follows:
./Test.sh: line 37: Sample01=: command not found
The no of alarms for this is 01
What is the issue with using the following in the code:
Sample$y= `expr $Sample$y + $tot_alarms `
For one, there should be no spaces around the assignment operator.
Not related to this, there is a space before the shebang on line 1 that should not be there.
Thanks i changed around the script, I am still puzzeled
echo $Sample$y+$tot_alarms | bc > Sample$y
echo $Sample$y
the debug gives the following
i need the foillowing Sample01=36774, Sample02=3333 .....
however when i try to add or assign contents to these variables it seems to use the index of the SampleXX
+ bc
+ echo 01+3674
+ 1> Sample01
+ echo 01
01
#!/bin/ksh
set -x
cat $parse_data | awk '/'$time$i'/ {for(x=0; x<=16; x++) {getline; print}print "--" }' > _hr.txt
for y in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 81 82 83 84 85
do
tot_alarms=`cat _hr.txt | grep -c "Sample=$y"`
echo "Totals no of alarms for Sample=$y for $time$i is =====> $tot_alarms"
echo $Sample$y+$tot_alarms | bc > Sample$y
echo $Sample$y
#totalAlarms=`expr $tot_alarms + $totalAlarms `
done
echo "Total no of alarms for this hour is : $totalAlarms"
done
+ + cat _hr.txt
tot_alarms=3674
+ echo Totals no of alarms for Sample=01 for 02-07-12:00 is =====> 3674
+ bc
+ echo 01+3674
+ 1> Sample01
+ echo 01
01