Hello,
I hope somebody can point out the error of my ways. I am trying to do a simple counting program reads through a list of domains (stored in a flat file referenced as $list) copies relevant lines from a huge logfile ($inp) to a temporary file ($tmp), produces a unique list of these elements($tmp2), reads through the unique file, line-by-line counting the number of repeats, and then repeats the whole thing with the next domain from $list.
I know it's "clunky", but it's the only way I could think of doing it (with my limited programming experience).
#!/usr/bin/ksh
####################################################
# Read a list of domains, scan the specified logs, #
# produce a list of the number of occurences, sort #
# by number of occurences. #
################################################MHT#
#
# Set initial variables
#
list=/sd/csmlist.txt
out=/frep/csmlist.log
tmp=/tmp/csmlist.tmp
tmp2=/tmp/csmlist2.tmp
inp=/maillennium/log/stats.2005022410
#
# start read loop
#
exec 0<$list
while read line
do
rm -f $tmp $tmp2
cat $inp | egrep -i '(fr=)(.*)('$line')( ra=)' | awk -F"fr=" '{print $2}' | awk -F"@" '{print $1}' >> $tmp
sort -u $tmp >> $tmp2
exec 0<$tmp2
while read uni
do
noe=`cat $tmp |grep $uni | wc -l`
echo $line " " $uni " " $noe
echo $line " " $uni " " $noe >> $out
done
echo "$line done"
done
#
# Exit processing
#
exit
The problem is that it partially works; it reads the first domain, finds the ID's that have been used and counts the number of times (as expected), but one it has finished with the first domain, and exits the 'inside' while loop, it also exits the 'outside' loop (apparently cleanly, as if it had read the last record).
I'm assuming this problem is do to with nesting while loops, but I'm not sure.
Any ideas?
Cheers,
Mark T.
I hope somebody can point out the error of my ways. I am trying to do a simple counting program reads through a list of domains (stored in a flat file referenced as $list) copies relevant lines from a huge logfile ($inp) to a temporary file ($tmp), produces a unique list of these elements($tmp2), reads through the unique file, line-by-line counting the number of repeats, and then repeats the whole thing with the next domain from $list.
I know it's "clunky", but it's the only way I could think of doing it (with my limited programming experience).
#!/usr/bin/ksh
####################################################
# Read a list of domains, scan the specified logs, #
# produce a list of the number of occurences, sort #
# by number of occurences. #
################################################MHT#
#
# Set initial variables
#
list=/sd/csmlist.txt
out=/frep/csmlist.log
tmp=/tmp/csmlist.tmp
tmp2=/tmp/csmlist2.tmp
inp=/maillennium/log/stats.2005022410
#
# start read loop
#
exec 0<$list
while read line
do
rm -f $tmp $tmp2
cat $inp | egrep -i '(fr=)(.*)('$line')( ra=)' | awk -F"fr=" '{print $2}' | awk -F"@" '{print $1}' >> $tmp
sort -u $tmp >> $tmp2
exec 0<$tmp2
while read uni
do
noe=`cat $tmp |grep $uni | wc -l`
echo $line " " $uni " " $noe
echo $line " " $uni " " $noe >> $out
done
echo "$line done"
done
#
# Exit processing
#
exit
The problem is that it partially works; it reads the first domain, finds the ID's that have been used and counts the number of times (as expected), but one it has finished with the first domain, and exits the 'inside' while loop, it also exits the 'outside' loop (apparently cleanly, as if it had read the last record).
I'm assuming this problem is do to with nesting while loops, but I'm not sure.
Any ideas?
Cheers,
Mark T.