Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

strange !!!
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

BEGIN
{
print "loading";
}


{
for(i=1;i<= NR; i++)
{
for(j=1;j<= NF ;j++)
{
if ($j !~ /[+-]?[0-9]+(\.[0-9]*)?([Ee][+-]?[0-9]+)?/
 )
{
print "error in numeric format at position $j , $i ";
exit;
}
}
}
}


END
{
print "loaded";
}


if i remove begin and end i get this error

gawk: awk:5: (FILENAME=eg.txt FNR=1) fatal: division by zero attempted

Report this thread to moderator Post Follow-up to this message
Old Post
dada
03-20-04 01:23 AM


Re: strange !!!
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][+-]?	
1;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

Report this thread to moderator Post Follow-up to this message
Old Post
Ulrich M. Schwarz
03-20-04 01:23 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 11:26 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.