Piping Unix Variable Array values into AWK

#ksh

Here is my code:

ERRORLIST="43032 12001 12002 12003 12004 34019 49015 49016 49017 49018 49024 49025 49026 58004 72003 12005 12006 12007 12008 12011 12012 16024 16023"

for ERROR in ${ERRORLIST}
do
awk -v l="$lastdate" '/^....-..-../&&$0>l{d=$0}d&&/Error: '"${ERROR}"'/{print d,$0}' $logfile > $tempfile
done

for some reason its only finding the last value in my array 16023 and not picking up 16024. Any help appreciated! thanks

You should append to the file instead of overwriting the file

awk -v l="$lastdate" '/^....-..-../&&$0>l{d=$0}d&&/Error: '"${ERROR}"'/{print d,$0}' $logfile >> $tempfile

Or put it after done:

..
  awk -v l="$lastdate" '/^....-..-../&&$0>l{d=$0}d&&/Error: '"${ERROR}"'/{print d,$0}' $logfile 
done > $tempfile

omg i should also try to remember to keep breathing with that mistake. Thank you both though