I know the answer has been accepted, but this is simply wrong.
Because you want to use awk as a parser, not as code.
Awk should be used on some Unix channels and should not be used on any logic.
I had the same problem and solved it in awk as follows:
NLINES = wc -l <file>
cat | awk -v nl = $ {nlines} '{if (nl! = NR) {print $ 0, ",", "\";} else {print;}}' → $ {someout}
There is an important point here: pipes, flash and RAM.
If you make awk spit out your output, you can pass it on to the next processor.
If you use getline, and in particular in a loop, you may not see the end.
getline should be used only for a line and possible dependence on the next line.
I love awk, but we can't do everything with it!
Edition:
For whom I voted for the answer, I just want to introduce this script:
#! /bin/sh
And, of course, the first results:
tmp]$ ./awkRun.sh SUM Getln 0.78 SUM Plain 0.71 SUM Getln 7.2 SUM Plain 6.49 SUM Getln 35.91 SUM Plain 32.92
If you save about 10% of the time just because of getline.
Consider this in a more complex logic, and you can get even the worst image. This simple version does not count memory. And it seems they do not play a role for this simple version. But memory can also play a role if you move on to more complex logic ...
Of course, try on your car.
That is why I suggested considering other options in general.