A standard approach could be:
what_we_want='123456789'
context='firstname'
distance=10
grep -E -e "${context}" -C "${distance}" file_to_look_into | grep -E -e "${what_we_want}" -C "${distance}"
The first ensure that we only look $distance lines around $context matching lines, the 2nd then see if it find "$what_we_want" in those 2*$distance+1 lines. If you just want the matching line as a result, drop the -C "${distance}" from the 2nd grep.
The first grep ensures that we only look $distance lines around $context matching lines. The 2nd then sees if it find $what_we_want in those 2*$distance+1 lines.
If you just want the matching line as a result, drop the -C "${distance}" from the 2nd grep.