in reply to Extracting data from a messy file (slow performance)

At the risk of annoying the Perl Monks, and talking about not perl things, your script is not very optimised.

1. Use AWK..it was designed for this sort of thing.
2. If you really want to use shell, look into cutting down the number of external call to grep/egrep/wc, etc, and don't post here...
i.e.
if [ `echo $line | grep "vmstat 2 60" | wc -l` -eq 1 ]
remove one external call to wc
if [ `echo $line | grep -c "vmstat 2 60"` -eq 1 ]
the same goes for setting 'stat=1'. Do it in one loop.