ITEM: D5784L
awk: field $() is not correct
Question:
I am writing an awk script and for several lines of the script
I receive the error:
awk: field $() is not correct
In some cases, by rearranging the lines (ie removing tabs, etc...)
these errors go away. What is causing the error and what can
I do to correct it?
Response:
The error can be recreated as simply as this:
BEGIN {
print scanning file...
}
{print $0}
END {
print all lines processed
}
If this is in a file called awktest, the command
awk -f awktest filetocat
will exit normally if the last line of filetocat is a carriage return.
In other words, if EOF is reached before a carriage return, the error
occurs.
The problem apparently does not occur if you have FS = " "
(default) instead of setting FS = "". When awk runs, it parses each
line for arguments. By setting FS = "" the customer was hoping to
increase efficiency by not having to parse the list of arguments
into fields.
Adding the return at the end of the last line
clears up all occurrences of the error.
Support Line: awk: field $() is not correct ITEM: D5784L
Dated: August 1993 Category: N/A
This HTML file was generated 99/06/24~13:30:56
Comments or suggestions?
Contact us