Checking Files with a Shell Script

Hey everyone,

I'm writing a shell script that needs to loop thru a directory and check a defined type of files(.df).

I use "checkfile.x" which is a compiled program to check those files. Sintaxis : checkfile.x DatefileName.df

The program displays something like this:
File: kanswer.df - start search
File: kanswer.df has 1 records
File: kaprvlmt.df - start search
File: kaprvlmt.df has 72 records
File: kapyhour.df - start search
File: kapyhour.df - Last record is NOT a ZZZ record
File: kapyhour.df has 90 records
File: kaseitem.df - start search
File: kaseitem.df has 173 records

Here comes the catch, what I would like to do is, get the files with "Error" (we know if a file has an error buy checking the status for example the legend "Last Record not a ZZZ record" or "Error") and display them so the user will know which files nee do to be fixed. So if we continue working with the example included I should get something like this:
File: kapyhour.df - start search
File: kapyhour.df - Last record is NOT a ZZZ record

And nothing else.

Ok here is what I got so far:
1-Access the files in the directory
2-Check them with the "checkfile.x" program
3-Save the result on $FILE_W_ERR
4-Validate if there's one of the legends("Error" or "ZZZ").
5-If true display the checkfile result else next record.

# Goes thru the data files
for FILE in *.df
do

    # Checks each of the files and stores the result
    FILE_W_ERR=`checkfile.x $FILE`

    #Looks for the Err message in the return value of checkfile
    INSTR=`echo "$FILE_W_ERR" | egrep -c "ZZZ"`

    # Validate if the checkfile found any errors
    if [ "$INSTR" -ne "0" ]
    then

        # Display file with possible Error
        echo $FILE_W_ERR
        echo #INSTR

    fi

done

This is returning this:
File: kanswer.df - start search
File: kanswer.df has 1 records
File: kaprvlmt.df - start search
File: kaprvlmt.df has 72 records
File: kapyhour.df - start search
File: kapyhour.df - Last record is NOT a ZZZ record
File: kapyhour.df has 90 records
File: kaseitem.df - start search
File: kaseitem.df has 173 records

The exact same result.

I ran out of ideas here, please let me know if you have something I can use to get this done.

Thanks in advance everyone !

If you mean "display" as in "edit" you could for instance:

#!/bin/bash
[ $# -eq 0 -o -d "$1" ] || { echo "${0//*\//}: dirname"; exit 1; }
find "$1" -type f -iname \*.df | while read FILE; do
 # Results go to stdout, and
 checkfile.x "${FILE}" 2>/dev/null
 # ...provided "checkfile.x" uses proper exit codes, you could...
 [ $? -eq 0 ] || vi "${FILE}"; wait
done
exit 0