Hi,
The code snippet you gave does not show what it is you are trying to do. It looks like the hard way to do something (if intervals is the only file that is used).
If it is the only file, you do not need the
while getline contruct. If there is another file, using the getline twice is too expensive (has to open, read, close the file twice).
If intervals is the only input file, try something like this:
awk '
{ print $0}
' intervals
The above snippet isn't too usefull, it just prints all the lines and fields. It's just a very simple example.
If more then one file is needed, some thing like this example is a way to handle this:
Code:
#!/usr/bin/ksh
awk 'BEGIN { FS=":" ; OFS="\t" ; print "User\tGID\tUser Name\tHome Dir\t"
while ( getline < "/etc/group" > 0 )
{ GRID[$3] = $1 }
}
{ print $1 , GRID[$4] , $5 , $6 }
END { print "\n End of Report \n" }
' /etc/passwd
The input files are /etc/passwd and /etc/groups, the human readable name of the group is printed instead of the GID number.
The BEGIN part reads the content of /etc/group and uses fields 3 and 1 to set up an array. The array is used to print the group name in the 'normal' (middle) part of awk.
I can explain why you have to press ctrl-d at the end: You read a line at the time (2nd getline), but do not check for an EOF. You pressing ctrl-d (=EOF) tells getline that it is done.
Hope this clears things up a bit.