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

question in dealing with variable no of fields
hi,

i wud like to check if all the records have same number of fields .

i.e

for eg if the file has,
1 2 3
4 5 6
7 8 9
i will print ok
if it is like

1 2
3 4 5
4 5 6
i willl rpint error and exit


also when i tried a simple program i got the following error wat does it mea
n


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


the version gawk 3.1.0

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


Re: question in dealing with variable no of fields
usenetdada@yahoo.com (dada) writes:

> hi,
>
> i wud like to check if all the records have same number of fields .

The following worked, at least on the test data you gave:

NR == 1                 { fields_per_record = NF; worked=2;}
NF != fields_per_record { worked=0;
print "Error: line", NR,
"had",NF,"fields",
"where I expected", fields_per_record ".",
"The offending line was:\n",$0;
# exit -1;
}
END                     { if (worked)
print "ok";
else exit -1;
}

If you comment in the first "exit" line, we will fail as soon as the
first error comes up, but the rest of the input data will remain in
the stream.

With greetings from .de,
Ulrich
-- 
Salesman: The glass is future-proof and can handle a 100% capacity upgrade.
Tech support: You need a water upgrade.           -- JM, in the sdm

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


Re: question in dealing with variable no of fields
In article <f7851403.0402290314.1632b582@posting.google.com>,
dada <usenetdada@yahoo.com> wrote:
...
>also when i tried a simple program i got the following error wat does it mean[/colo
r]

Any particular program, or is it all programs?

>gawk: temp:4: (FILENAME=eg.txt FNR=1) fatal: division by zero attempted

It probably means that division by zero was attempted, at line 1 of data
file "eg.txt", and that gawk flagged this as a fatal error.  This probably
occurred at line 4 of script file "temp".

Of course, that's just a layman's interpretation...


Report this thread to moderator Post Follow-up to this message
Old Post
Kenny McCormack
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 04:55 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.