Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #191205

Re: scriptable way to list packages that are not installed

From davidson <davidson@freevolt.org>
Newsgroups linux.debian.user
Subject Re: scriptable way to list packages that are not installed
Date 2018-01-16 20:40 +0100
Message-ID <v8Ffr-4O1-7@gated-at.bofh.it> (permalink)
References <v7HCF-6FF-1@gated-at.bofh.it> <v7K7v-8kR-1@gated-at.bofh.it> <v7Khb-8o5-3@gated-at.bofh.it> <v7WV4-85f-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Sun, 14 Jan 2018, Vasyl Vavrychuk wrote:

> Hi, John,
>
> On Sun, Jan 14, 2018 at 8:48 AM, john doe <johndoe65534@mail.com> wrote:
>> On 1/14/2018 7:28 AM, john doe wrote:
>>
>> $ dpkg-query -W -f='${db:Status-Abbrev}${binary:Package}\n' awk git gawk
>> cmake 2>&1 | awk '!/^ii/ || !/^un/{print $6}'
>> git
>> gawk
>> cmake
>
> I also tried to parse stderr, but then I realized that relying on the output
>
>   dpkg-query: no packages found matching
>
> is not correct since it might be localized and is not suitable for scripting.

You could just discard the stderr, and take the complement of the hits
from dpkg-query, relative to the supplied arguments:

show-installed () {
     dpkg-query -W -f='${db:Status-Abbrev}${binary:Package}\n' "$@" |
     awk '/^ii/ {print $2}'
}

show-absent () {
     universe=("$@")
     diff <( IFS=$'\n' ; sort <<<"${universe[*]}" ) \
 	<( show-installed "${universe[@]}" 2>/dev/null ) |
     sed -n 's/^< //p'
}

$ dpkg-query -l not-a-real-package exim4 mksh xorg bash xterm chromium
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                   Version          Architecture     Description
+++-======================-================-================-=================================================
ii  bash                   4.4-5            amd64            GNU Bourne Again SHell
un  exim4                  <none>           <none>           (no description available)
ii  mksh                   54-2+b4          amd64            MirBSD Korn Shell
ii  xorg                   1:7.7+19         amd64            X.Org X Window System
ii  xterm                  327-2            amd64            X terminal emulator
dpkg-query: no packages found matching not-a-real-package
dpkg-query: no packages found matching chromium

$ show-installed !*
show-installed not-a-real-package exim4 mksh xorg bash xterm chromium
dpkg-query: no packages found matching not-a-real-package
dpkg-query: no packages found matching chromium
bash
mksh
xorg
xterm

$ show-absent !*
show-absent not-a-real-package exim4 mksh xorg bash xterm chromium
chromium
exim4
not-a-real-package

(It is above my pay grade to tell whether "sort" needs its flags
tweaked to sort identically to dpkg on arbitary package names.)

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

scriptable way to list packages that are not installed Vasyl Vavrychuk <vvavrychuk@gmail.com> - 2018-01-14 05:00 +0100
  Re: scriptable way to list packages that are not installed john doe <johndoe65534@mail.com> - 2018-01-14 07:40 +0100
    Re: scriptable way to list packages that are not installed john doe <johndoe65534@mail.com> - 2018-01-14 07:50 +0100
      Re: scriptable way to list packages that are not installed Vasyl Vavrychuk <vvavrychuk@gmail.com> - 2018-01-14 21:20 +0100
        Re: scriptable way to list packages that are not installed Michael Lange <klappnase@freenet.de> - 2018-01-14 23:10 +0100
        Re: scriptable way to list packages that are not installed davidson <davidson@freevolt.org> - 2018-01-16 20:40 +0100
          Re: scriptable way to list packages that are not installed davidson@freevolt.org - 2018-01-16 21:00 +0100
            Re: scriptable way to list packages that are not installed Charlie Gibbs <cgibbs@surfnaked.ca> - 2018-01-17 03:20 +0100
              Re: scriptable way to list packages that are not installed The Wanderer <wanderer@fastmail.fm> - 2018-01-17 05:20 +0100
                Re: scriptable way to list packages that are not installed John Hasler <jhasler@newsguy.com> - 2018-01-17 05:50 +0100
              Re: scriptable way to list packages that are not installed Darac Marjal <mailinglist@darac.org.uk> - 2018-01-17 20:40 +0100
                Re: scriptable way to list packages that are not installed davidson <davidson@freevolt.org> - 2018-01-17 21:10 +0100
                Re: scriptable way to list packages that are not installed Charlie Gibbs <cgibbs@surfnaked.ca> - 2018-01-18 07:20 +0100
          Re: scriptable way to list packages that are not installed davidson <davidson@freevolt.org> - 2018-01-16 22:40 +0100
  Re: scriptable way to list packages that are not installed Eduardo M KALINOWSKI <eduardo@kalinowski.com.br> - 2018-01-14 11:40 +0100
  Re: scriptable way to list packages that are not installed Roberto C. Sánchez <roberto@debian.org> - 2018-01-14 14:00 +0100
  Re: scriptable way to list packages that are not installed Bernd Gruber <begruber@mnet-online.de> - 2018-01-14 16:00 +0100

csiph-web