Hi,
i would suggest to first read in the whole file in three array, one for the serial, one for the user and one for the ipadd.
Code:
declare -a SERIAL ACCT IPADD
let count=0
while IFS=, read a b c
do
SERIAL[$count]=$a; ACCT[$count]=$b; IPADD[$count]=$c; ((count++))
done < file
This sets the internal field separator to "," and reads the three comma separate fields into the three variables which are pushed into the declared arrays.
Now you can search this array like this:
Code:
let i=0
while [[ $i -lt ${#SERIAL[@]} ]]
do
[[ ${SERIAL[${i}]} = W120* ]] && printf "%s %s\n" ${ACCT[${i}]} ${IPADD[${i}]}
((i++))
done
This loops trough the array. ${#SERIAL[@]} gives you the number of entries of an array. If a certain SERIAL is found, the corresponding data are output.
HTH Chris