#!/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
-->
Code:
#!/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.
|