question about grep, cut, and piping

Howdy folks,

I am fairly new to scripting but have lost of expirience in c++, pascal, and a few other. I am trying to complete a file search script that is sent a file name containing data to search that is arranged like this

"id","name","rating"
"1","bob","7"
etc

and an argument to search such as name=bob. My problem is that id and rating are both numerical so a simple grep won't work, so i need to search the correct field for the correct data. i need to then run a script(which i have already written and tested to work) that will accept the line numbers and the file name to print the lines that match. It is there where i am stuck.

Any suggestions how i can correctly print only the lines where the correct field matches? i can just forget the print lines script if there is an easier way that i missed. thanks for any help!

Mike

#!/bin/sh
file=$1
field=`echo $2 | cut -d '=' -f 1`
value=`echo $2 | cut -d '=' -f 2`
fields=`head -1 $file`

fieldnum=0
thisfield=""
while [ "$thisfield" != "$field" ]
do
  fieldnum=`expr $fieldnum + 1`
  thisfield=`echo $fields | cut -d ',' -f $fieldnum`
done

tail +2 $file | while read line
do
  checkfield=`echo $line | cut -d ',' -f $fieldnum`
  if [ "$checkfield" = "$value" ]
  then
    echo $line
  fi
done

Untested
Usage:
scriptname.sh filename '"fielname"="value"'

Note the single ticks to protect the double quotes.

You could probably add some smarts to prevent it parsing the " symbols at all, making the whole thing a bit less clunky.