Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using "getline" in a while loop 1

Status
Not open for further replies.

carrotop

Programmer
May 14, 2002
1
US
I am trying to read one line at a time from the file “filelist” using “getline”.


$ cat filelist
mrrb_bed_typ_lkup;Y;v01r00;brmvx301
mrrb_drg_benchmark;Y;v01r00;brmvx302
mrrb_hin_mkt_lkup;Y;v01r00;brmvx303
mrrb_icd_procd_lkup;Y;v01r00;brmvx304
mrrb_msa_lkup;Y;v01r00;brmvx305


$ vi awk_list
#!/usr/bin/awk -f

set -vx

while ( (getline var < &quot;filelist&quot; ) > 0) {
print var
}


$ .awk_list

syntax error The source line is 8.
The error context is
>>> while <<< ( (getline var < &quot;filelist&quot; ) > 0) {
awk: Quitting
The source line is 8.
 
You need a pair of {} around the while. BTW, what does set -vx do? I have never seen it before.

{
while ( (getline var < &quot;filelist&quot; ) > 0) {
print var
}
} CaKiwi
 
I guess the OP confuses awk with shell => 'set -xv' vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Will this work in your situation?
gawk 3.1 here.

awk ' {
i++
printf &quot;Looking at line no: %d::%s\n &quot;, i, $0
printf &quot;Continue(y): &quot;
getline yvar < &quot;-&quot;
if (yvar ~ /[Yy]/) {
#doesn't matter
} else {
exit
}
}' filelist
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top