i'm trying to basically read every line of a file, doesn't really matter in what order, and look for two fields that match a pattern (dest=M,type=N) and return the third field, something like:
dest1 type1 .99
dest2 type2 2.34
dest3 type3 .50
To do this I'd have to be able to go back to the beginning of the file once it reaches the end because when i call the function with a diferent destination and type it starts where it left off. And once it reaches the end of the file it goes crazy. I tried modifying the NR,FNR variables but that didn't do anything
The function is something like:
awk '
function price(dest,type)
{
do{
getline pri < "Rates"
split(pri,a," "
}while ((a[1]!=dest)&&(a[2]!=type))
return a[3]
}
.
.
.
where "Rates"
dest1 type1 .99
dest2 type2 2.34
dest3 type3 .50
Any help would be thanked profusely.
dest1 type1 .99
dest2 type2 2.34
dest3 type3 .50
To do this I'd have to be able to go back to the beginning of the file once it reaches the end because when i call the function with a diferent destination and type it starts where it left off. And once it reaches the end of the file it goes crazy. I tried modifying the NR,FNR variables but that didn't do anything
The function is something like:
awk '
function price(dest,type)
{
do{
getline pri < "Rates"
split(pri,a," "
}while ((a[1]!=dest)&&(a[2]!=type))
return a[3]
}
.
.
.
where "Rates"
dest1 type1 .99
dest2 type2 2.34
dest3 type3 .50
Any help would be thanked profusely.