price.txt
file has two columns:(name and value)
Mary 134
Lucy 56
Jack 88
Marissa 37
Emily 85
Antony 99
range.txt
file also has two columns:(fruit and value)
apple 57
banana 62
orange 88
blueberry 98
The second column of range.txt
is ordered (from minimum to maximum)
My aim is to extract rows of price.txt
of which the values are within the range of values (57 - 98) in range.txt
file.
The expected result is as follows:
Jack 88
Emily 85
I try to solve this by using the following code, but I don't know how to select the first line and the last line of the specific column. The unclear parts of the code are between asterisks (**...**
):
awk 'FNR == NR {value=$2; **low=??; high=??**; next}
{if ($2>=**low** && $2<=**high** ) print $0}' range.txt price.txt
low
value. It seems that the $2 of the first file is the maximum value (98).awk 'FNR == NR {high=$2; if(NR==1) low=high; next} {if ($2>=low && $2<=high ) print $0}' range.txt price.txt