We all know that there are several built-in variables in awk utility like – NF, FS, NR, and positional variables like $0 … . I have an awk script where I am using getline functionality to get output of a command like below:
while ( ("ls -l" |& getline) > 0) {
}
while ( ("ls -l" | getline) > 0) {
}
while ( ("ls -l" |& getline) > 0) {
}
while ( ("ls -l" |& getline var) > 0) {
}
Please let me know which of the AWK built-in variables I can infer inside the while loop. I tried accessing NR but it always gives me 0? Say I want to write something like below:
while ( ("ls -l" |& getline) > 0) {
if(NR == 1)
{
do something .. by parsing data via a Field Separator
}
}
See http://awk.freeshell.org/AllAboutGetline and make sure you fully understand it and have a lot of awk experience before being tempted to use getline. The example you give is almost certainly NOT a good candidate for using getline.