I wouldn't recommend it on a huge chunk of data, but I thought I'd try a bash solution. I'm not very bash-fluent, but this seems like the "obvious" way of handling things, "algorithmically speaking". This basically iterates over each file and searches for the good range. I've given some details in the comments.
The script must be executed this way:
$ ./script.sh [salaries] [ranges]
The salaries file contains Sam's, John's and Max's salaries, while ranges contains your ranges and ranks (2000 to 4000 is deputy, 4000 to 6000 is secretary, and so on).
test $# -ne 2 && exit 1
test ! -r "$1" -o ! -r "$2" && exit 2
# Open the salary file (3) and the ranges (4).
exec 3< "$1"
exec 4< "$2"
# Echo the salary headers.
read -d$'\n' headers <&3
echo "$headers" | tr -s ' '
# For each line in the salary file...
while read name salary; do
# Skip the ranges headers ("salary_min...").
read -d$'\n' skip <&4
# For each range...
while read min max rankname; do
# If the salary is within the range, print name and rank.
if [ "$salary" -ge $min -a "$salary" -lt $max ]; then
echo "$name $rankname"
# Reopen the range file for the next employee.
exec 4< "$2"
Note that my ranges checks are inclusive on the lower bound, but exclusive on the higher:
[ "$salary" -ge $min -a "$salary" -lt $max ]
You might want to change this line if it isn't the behaviour you're expecting. I also tried to open files as rarely as possible, but since bash does not handle file seeking, I still need to close/reopen the ranges file regularly. To be honest, I'd recommend a slightly lower level implementation, if you are to deal with very large files. C would be nice.