I need to output the sum of a grep results for a certain time, for now i hard coded the time grep but any help will be very much appreciated, my problem is i cant output the results on the script.If i use this line, it will give me an output of 1:cat *.log | egrep '2011-07-01 (04:[0][0-9]:[0-5][1-9]|04:10:00)' * | grep -ach '0110 478655 ..  51' | awk '{SUM += $1} END { print SUM }'and this line would give me an output of 0 :cat *.log | egrep '2011-07-01 (04:[1][0-4]:[0-5][1-9]|04:15:00)' * | grep -ach '0110 478655 ..  51' | awk '{SUM += $1} END { print SUM }'this code needs alot of improvements :while read linedocd $DIRta1=`cat *.log | egrep '2011-07-01 (04:[0][0-9]:[0-5][1-9]|04:10:00)' * | grep -ach '0110 478655 ..  51' | awk '{SUM += $1} END { print SUM }'`ta2=`cat *.log | egrep '2011-07-01 (04:[1][0-4]:[0-5][1-9]|04:15:00)' * | grep -ach '0110 478655 ..  51' | awk '{SUM += $1} END { print SUM }'`ta=$((ta1 + ta2))echo -e Results =  $ta donei wanted to add the results and put it on a while do statement, also i needed two grepping so i can sum up all the instances for a 15min cycle., any idea how to do a single grep statement instead?
Sum of grep results
grep;awk;date;time;arithmetic
If your problem is just making grep match a 15 minute window with one regex instead of two, try breaking it down like this:Change:egrep '2011-07-01 (04:[0][0-9]:[0-5][1-9]|04:10:00)' egrep '2011-07-01 (04:[1][0-4]:[0-5][1-9]|04:15:00)'To:egrep '2011-07-01 04:(0[0-9]|1[0-4]):[0-5][0-9]'That should match the 15 minute block starting at 00:00 and ending 14:59. For the next three blocks use these:# 15:00 to 29:59egrep '2011-07-01 04:(1[5-9]|2[0-9]):[0-5][0-9]'# 30:00 to 44:59egrep '2011-07-01 04:(3[0-9]|4[0-4]):[0-5][0-9]'# 45:00 to 59:59egrep '2011-07-01 04:(4[5-9]|5[0-9]):[0-5][0-9]'