foreach i ('ls -d APPL_RMKS_RCV* ') grep -v 'NOT|INVALID|MUST|ERROR' $i | grep - >> ${good_ones} grep 'NOT|INVALID|MUST|ERROR' $i | grep - >> ${bad_ones} end