On 3/16/06, Vidyadutt S <[EMAIL PROTECTED]> wrote:
> 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".

This problem is due the piping in the following line ;)

>   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"

You can avoid it by changing the about code to..

 for RECORD in `cat tst|awk '{print NF}'`;
 do
   if [ $RECORD -ne $FIELDS ]; then
       NM_CNT=$(($NM_CNT+1))
    printf "NM_CNT=$NM_CNT\n"
   fi
 done



--
___________________________________________

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/S C++++ P+ L+++(++++) E++(+++) W++ N+++ w---  e+++ a--
y d- s:++ r-- b+Y+ G+++
------END GEEK CODE BLOCK------
decode with www.ebb.org/ungeek

--
http://mm.glug-bom.org/mailman/listinfo/linuxers

Reply via email to