Hello Luggers
   
  The following function takes 2 arguments, "a filename" and "number of 
fields". It checks the number of field of each record against the second 
argument. If it doesn't match, it increase the value of the variable "NM_CNT" 
by 1. But, once the loop has finished execution, the value of this variable 
gets reset to "0".
   
  verify_record()
{
  FILE=$1
  FIELDS=$2
  cat $FILE | while read RECORD
  do
    if [ `printf "$RECORD" | awk -F\| '{ print NF }'` -ne $FIELDS ]; then
      NM_CNT=`expr $NM_CNT + 1`
      printf "NM_CNT=$NM_CNT\n"
    fi
  done
  printf "NM_CNT=$NM_CNT\n"
  return $NM_CNT
}
   
  Here is the output. The maximum value of NM_CNT in the loop is 2, but once it 
comes out of the loop, its value becomes "0".
   
  $ verify_record temp/a 2
(in loop)NM_CNT=1
(in loop)NM_CNT=2
NM_CNT=0
   
  Can anybody help me to solve this problem? Currently, I redirect the value of 
this variable in a file for using it outside the function. I run this script 
under the "sh" environment on SUN Solaris 8.
   
  Regards
  SV

                                
---------------------------------
 Jiyo cricket on Yahoo! India cricket
Yahoo! Messenger Mobile Stay in touch with your buddies all the time.
-- 
http://mm.glug-bom.org/mailman/listinfo/linuxers

Reply via email to