Ive been at the command line for some time. Back as far as SCO and Interactive Unix. I have always used this construct without issues. I want to isolate the ip / field 1. As you can see .. the first line is "skipped".
This works as expected. But again, whats changed ?
Even though this discussion about awk intrinsics is fascinating and my horizon was expanded (a collective "thank you" to you all in this thread), just for the record:
Wouldn't the usage of shell means (variable expansion or field splitting) be less costly than the use of an external program? I suppose thread-o/p does something with the values once he split them, something along the lines of:
awk -F',' '{print $1}' datafile | while read IP ; do ..... done
In such a case it might be easier to do:
while IFS=, read IP junk ; do ..... done < datafile
or, depending on what else is done:
while read LINE ; do
IP="${LINE%,*}"
.....
done < datafile
I have not looked at the gawk code (and for legal reasons choose not to do so). But one might guess that a function named set_NF() would set the value of the awk NF variable. Are you really telling me that gawk sets the value of NF for a new input record BEFORE parsing that record into fields??? That makes absolutely no sense to me! How can it set NF before it parses a record into fields to determine what value should be assigned to NF ? One might expect that a function like that would be called to parse an input line or AFTER parsing an input line depending on the context. In the context of reading a new record from an input file at the start of a new cycle and in the context of using the awk command:
getline
with no argument naming a variable to be assigned and with no input redirection that should happen (as well as setting $x (for 0 <= x <= NF ), NR , and FNR ). In the context of reading a new record from an input file using the awk command:
getline variable
with a variable, but no input redirection, NR and FNR should be updated, but NF and the current record's fields should not be modified. In the context of reading a new record from an input file using the awk command:
getline variable < file
or
command | getline variable
with a variable and with input redirection, none of the variables NF , NR , FNR , nor the current record's fields should change.