cancel
Showing results for 
Search instead for 
Did you mean: 

data processing

SOLVED
Go to solution
Cherry Castro
Occasional Visitor

data processing

Hi Guyz,
I have a file containing three columns
1 10 A
11 20 B
21 30 C.
I was about to write a script that reads an input number then produce result based on the file if it is between the first two columns.
Example if i inputed 5. It is between 1 and 10 (based on the file) and will give me an output of A (which is the assigned letter on the third column).
Can someone help me how to do this? that after reading a number. it will search each line in the file to which the number is in between those ranges then register the output of assigned letter from the 3rd column.

Thanks in advance
Cheers
2 REPLIES
Hein van den Heuvel
Honored Contributor
Solution

Re: data processing

Here is a sample solution.
The table file is call x.txt and read as main data.
The target variable is passed as a variable on the command line.

$ awk -v target=6 'target > $1 && target < $2 {print $3; x++} END {if (!x) print "NOT IN RANGE"}' x.txt

If the targets also come from a file, the you may want to read the table in an AWK or PERL 'BEGIN' section first and then read the values and process in the main block.

hth,
Hein.

Cherry Castro
Occasional Visitor

Re: data processing

Thanks so much. This is exactly what resolves my case. cheers