the part that take the most of the time is the following code.
Code:
function line_count
{
COUNT=`echo $1 | awk -F\| '{print NF}'`
if [ "$COUNT" != "$2" ]
then
error_log "File $FN: Validation failed at line $LINENUM. Expected $2, getting $COUNT"
return 5
fi
}
function validate_line
{
if [ "$1" = "$FIRST_LEVEL_HEAD" ]
then
line_count "$2" $FIRST_LEVEL_COUNT
return $?
elif [ "$1" = "$SECOND_LEVEL_HEAD" ]
then
line_count "$2" $SECOND_LEVEL_COUNT
return $?
else
error_log "File $FN: Line $LINENUM head is not regconised"
return 5
fi
}
function validate_file
{
trace_log "Start to validate $FN..."
LINENUM=0
ERROR=0
while read LINE
do
LINENUM=`expr $LINENUM + 1`
LINE_HEAD=`echo $LINE | awk -F\| '{print $1}'`
validate_line $LINE_HEAD "$LINE"
if [ ! $? -eq 0 ]
then
ERROR=1
fi
done < $1
if [ ! $ERROR -eq 0 ]
then
return 7
fi
}
validate_file $FILE