Hi Friends,
I wrote the below shell script to generate a report on alert messages recieved on a day. But i for processing around 4500 lines (alerts) the script is taking aorund 30 minutes to process.
Please help me to make it faster and improve the performace of the script. i would be very happy if this report gets generated within 5 mins - if possible
Below is my shell script
cp a_15.txt abc_15.txt && cp a_15.txt xyz_15.txt
total_word_count=0; match_word_count=0; alerts_matched=0;
while read outer_line
do
echo -e "$outer_line"
total_word_count=`echo $outer_line |tr '[ : .' ' ' |awk '{ print NF} '`
outer_line=`echo $outer_line |tr '[ : .' ' '`
##
while read inner_line
do
###
for word in $outer_line
do
echo $inner_line |grep -i -w "$word" 1>/dev/null
if [ $? -eq 0 ];then
match_word_count=`echo $match_word_count + 1|bc`
else
:
fi
done
###
match_pcnt=`echo "scale=2; $match_word_count/$total_word_count*100"|bc |awk -F"." '{print $1}'`
if [ $match_pcnt -ge 66 ];then
alerts_matched=`echo $alerts_matched + 1|bc`
inner_line=`echo $inner_line| tr '[ : .' '.'`
sed -i "s/$inner_line//g" ./abc_15.txt
sed -i '/^$/d' ./abc_15.txt
else
:
fi
match_word_count=0;
match_pcnt=0
done <./abc_15.txt
##
echo -e "\nALERTS_MATCHED: $alerts_matched\n\n"
alerts_matched=0;
cat ./abc_15.txt >./xyz_15.txt
done <./xyz_15.txt >APS.out
---------- Post updated at 10:00 AM ---------- Previous update was at 09:55 AM ----------
The alert messages (4000 lines) will be like below
ERROR (19:58:50,781 ERROR Thread-37-RunnerPool-Fast RamPricingQueryRunner.run:493 Got exception parsing VAN query result for product [APS .Q])
ERROR (19:45:40,529 ERROR Thread-26-RunnerPool-Std RamPricingQueryRunner.run:493 Got exception parsing VAN query result for product [APS .Q])
ERROR (01:31:24,073 ERROR Thread-214 STAbstractComputable.getComputeResult:114 Cycle detected at com.sample.es.calcrules.newstyle.RuleAwareMarketDataHolder@12345, key=rules|APS .Q, subject=APS .Q, , rule=com.sample.es
The report i want looks like below
ERROR (19:58:50,781 ERROR Thread-37-RunnerPool-Fast RamPricingQueryRunner.run:493 Got exception parsing VAN query result for product [APS .Q])
ALERTS_MATCHED: 300
ERROR (19:45:40,529 ERROR Thread-26-RunnerPool-Std RamPricingQueryRunner.run:493 Got exception parsing VAN query result for product [APS .Q])
ALERTS_MATCHED: 55
ERROR (01:31:24,073 ERROR Thread-214 STAbstractComputable.getComputeResult:114 Cycle detected at com.sample.es.calcrules.newstyle.RuleAwareMarketDataHolder@12345, key=rules|APS .Q, subject=APS .Q, , rule=com.sample.es
ALERTS_MATCHED: 700