If you've ever tried to use a while-loop like this, you've experienced some frustration.
#!/bin/sh
RESULT=
cat db | while read index color; do
test "$index" = 2 && RESULT="$color"
done
echo "Index 2 is \"$RESULT\""
Where I'm using this file named db:
1 red
2 green
3 blue
When you run...