# A few bash one-liners that I found helpful when dealing with mismatched package versions:



## byrnejb (Jun 5, 2020)

I developed these while tracking down inconsistencies due to a partially backed out pkg upgrade.  Someone else may find them useful.  And I will be able to recover them from here when I forget how to do this:

List all installed packages against repository packages (check version consistency):

```
for P in $(pkg info | cut -w -f 1); \
    do echo "$P  $(pkg search $(echo $P  | sed 's/+/[+]/g' ) | cut -w -f 1)" ; done
```

List all installed packages that do not match the repository version:

```
for P in $(pkg info | cut -w -f 1); \
  do echo "$P  $(pkg search $(echo $P  | sed 's/+/[+]/g' ) | cut -w -f 1)" ; \
  done | awk 'NF==1{printf "%s\n", $0}' - | sort # <== '-' use standard in to awk
```

List all installed packages by install date (yyyy mmm dd):

```
for P in $(pkg info | cut -w -f 1); \
    do pkg info $P | grep -i 'name \|version \|installed ' | \
    sed -n 1,4p | paste -s -d':' - | tr ":" " " | cut -w -f2,4,8,9,13 ; done | \
    awk '{printf "%s %s %s  %s-%s\n", $5,$3,$4,$1,$2}' | sort -k1nr -k2Mr -k3nr
```

List all installed packages that match the repository versions

```
for P in $(pkg info | cut -w -f 1); \
    do echo "$P  $(pkg search $(echo $P  | sed 's/+/[+]/g' ) | cut -w -f 1)" ; \
    done |  sort | awk '{if($1!=$2)print $1 $2}'
```

_Note: the construct:_`$(echo $P  | sed 's/+/[+]/g' )` _is used to avoid the error:_`pkg: sqlite error while executing iterator in file pkgdb_iterator.c:1080: Invalid regex` _encountered when searching for package names and versions containing the character *+*.

For Example:_

```
pkg search 'libsigc++-2.10.2'
pkg: sqlite error while executing iterator in file pkgdb_iterator.c:1080: Invalid regex

pkg search $(echo libsigc++-2.10.2 | sed 's/+/[+]/g')
libsigc++-2.10.2               Callback Framework for C++
```


----------



## SirDice (Jun 8, 2020)

byrnejb said:


> List all installed packages against repository packages (check version consistency):


`pkg version -vR` or `pkg version -vI` (Note the difference between `-R` and `-I`: pkg-version(8)).



byrnejb said:


> List all installed packages that do not match the repository version:


`pkg version -vRL=` or `pkg version -vIL=` 



byrnejb said:


> List all installed packages that match the repository versions


`pkg version -vRl=` or `pkg version -vIl=`


----------

