| Ulrich M. Schwarz 2004-03-19, 8:23 pm |
| usenetdada@yahoo.com (dada) writes:
> This script checks whether all numbers in file are proper numbers.
> The script seems to be perfectly ok but im getting error messages .
>
> ! /usr/bin/gawk
You're missing a "#" here. gawk will try to evaluate this line,
possibly dividing usr by bin in the process. With usr and bin 0, this
will, of course, fail.
>
> BEGIN
at least my gawk 3.10 does not accept newlines between rule and action
and hence fails with "BEGIN must have an action part". Moving the
following "{" into this line fixes that.
> {
> print "loading";
> }
>
> {
> for(i=1;i<= NR; i++)
This variable is never used. It looks like you want to walk through
all lines that you have already checked again. I don't quite see the
point of that right now.
> {
> for(j=1;j<= NF ;j++)
> {
> if ($j !~ /[+-]?[0-9]+(\.[0-9]*)?([Ee][+-]?[0-9]+)?/ )
> {
> print "error in numeric format at position $j , $i ";
This will print
error in numeric format at position $j , $i
which is not very helpful as far as error messages go. Maybe you want
to move the " from after $i to in front of $j and replace $i with NR?
Because of the outer for loop, i will be pretty much any number, and
there will quite possibly not be a field number i in your current line.
> exit;
> }
> }
> }
> }
>
> END
> {
> print "loaded";
> }
With greetings from .de,
Ulrich
--
"Usenet. It's all fun and games until someone gets squirted in the
eye with Ann's breast milk." -- Mr. Cow in sb
|