I am using the getline x < file in the BEGIN{} section of an awk script to read an auxiliary file and populate an array which will be used to supply values in the main loop. The auxiliary files have inconsistent formats -- both " " and tab delimiters and arbitrary numbers of blank lines. In order to assign the correct index numbers to my created array I need to ignore blank lines within the getline loop but this has proved difficult. This code:
BEGIN {
...
cnum=1;
while (getline c < file > 0) {
if (c ~ /^$/ || c == " " || c == "") {
print "Blank line"
} else {
split(c,ca)
array[cnum]=ca[1]
cnum++
}
}
close(file);
...
}
Still seems to count the blank lines and increments the index cnum.
I need to be able to deal with arbitrary spacing so I can't simply adjust the index.
Any suggestions welcome.
This is awk under linux FC12 so I assume it is == Gawk.
BEGIN {
...
cnum=1;
while (getline c < file > 0) {
if (c ~ /^$/ || c == " " || c == "") {
print "Blank line"
} else {
split(c,ca)
array[cnum]=ca[1]
cnum++
}
}
close(file);
...
}
Still seems to count the blank lines and increments the index cnum.
I need to be able to deal with arbitrary spacing so I can't simply adjust the index.
Any suggestions welcome.
This is awk under linux FC12 so I assume it is == Gawk.