Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageusenetdada@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
Post Follow-up to this messageIn 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...
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.