pkg_info output?

Toni Schmidbauer toni at stderror.at
Mon May 2 02:45:45 PDT 2005


On Sat, Apr 30, 2005 at 11:48:35PM -0700, David Armour wrote:
> pkg_info | sort | sed -e 's/-[0-9].*$//' | uniq -c | grep -v '^[[:space:]]*1' 

0) pkg_info

list all packages installed

1) sort

sort the resulting list from 0) by package name

2) sed -e 's/-[0-9].*$//'

delete everything after a dash followed by a number
followed by everything else. so autoconf-2.59_2 becomes autoconf.

3) uniq -c 

from the manpage:

 -c      Precede each output line with the count of the number of times
         the line occurred in the input, followed by a single space.

so counts how often autoconf is in the list resulting from 2)

4)  grep -v '^[[:space:]]*1'

delete every line starting (^) with one or more space characters " "
followed by 1 in the list resulting from 3)

this deletes lines where only 1 version exists, e.g.:

     1 borg

>    3 autoconf
>    3 automake
>    6 docbook
>    2 gcc
>    2 glib
>    2 gtk
>    2 libtool
>    2 perl
>    2 xorg-fonts

so there are 3 versions of autoconf installed, 3 versions of
automake and so on.

the script is not quite correct because these two packages are
counted as two versions of xorg-fonts:

xorg-fonts-100dpi-6.8.2
xorg-fonts-75dpi-6.8.2

homework: find a version that works :-)

hth,
toni
-- 
Wer es einmal so weit gebracht hat, dass er nicht | toni at stderror dot at
mehr irrt, der hat auch zu arbeiten aufgehoert    | Toni Schmidbauer
-- Max Planck                                     |


More information about the freebsd-questions mailing list