script to search for packages by description (fwd)
Hello everyone.
Here is a small, ugly script that uses dpkg-awk to
search for packages by description. I don't know if
there is a similar package available, at least I
haven't seen one. If there is, just ignore this one.
As anyone can see from it, I don't know the first
thing about writing shell-scripts, but at least it
works (somehow).
Anyway, feel free to use/modify/package/edstroy/whatever
the script.
Regards,
Kristian Nylund
krnylund@io.yok.utu.fi
PS. If this isn't the first instance of this post it's
because I have some problems with my MTA. My apologies.
#!/bin/sh
UPPER=$(echo $1 | tr a-z A-Z)
LOWER=$(echo $1 | tr A-Z a-z)
if [ ! -x /usr/bin/dpkg-awk ]
then
echo "You must install dpkg-awk."
exit 0
fi
if [ -x /usr/bin/less ]
then
PGR=/usr/bin/less
else
PGR=/bin/more
fi
case "$1" in
"")
echo "Usage: dsearch <string> "
exit 1
;;
*)
dpkg-awk -f /var/lib/dpkg/available "Description: $1" -- Package Version Description > /tmp/dsearch.tmp
if [ ! $1 = $LOWER ]
then
dpkg-awk -f /var/lib/dpkg/available "Description: $LOWER" -- Package Version Description > /tmp/dsearch2.tmp
diff /tmp/dsearch.tmp /tmp/dsearch2.tmp |grep \^\> |cut -b 3- >> /tmp/dsearch.tmp
fi
if [ ! $1 = $UPPER ]
then
dpkg-awk -f /var/lib/dpkg/available "Description: $UPPER" -- Package Version Description > /tmp/dsearch3.tmp
diff /tmp/dsearch.tmp /tmp/dsearch3.tmp |grep \^\> |cut -b 3- >> /tmp/dsearch.tmp
fi
echo > /tmp/dsearch.dat
if [ $1 = $UPPER ] || [ $1 = $LOWER ]
then
echo -e "Number of available packages with description containg \n\"$LOWER\" or \"$UPPER\" : " >> /tmp/dsearch.dat
else
echo -e "Number of available packages with description containg \n\"$1\", \"$LOWER\" or \"$UPPER\" : " >> /tmp/dsearch.dat
fi
echo >> /tmp/dsearch.dat
cat /tmp/dsearch.tmp |grep Package |wc -l >> /tmp/dsearch.dat
echo >> /tmp/dsearch.dat
echo "------------ Listing alphabetically by package name ------------" >> /tmp/dsearch.dat
dpkg-awk -s "Package" -f /tmp/dsearch.tmp >> /tmp/dsearch.dat
$PGR /tmp/dsearch.dat
rm -f /tmp/dsearch*
;;
esac
exit 0
Reply to: