So optimieren Sie die Ausgabe von "dpkg -l"


10

Die von dpkg -l zurückgegebenen Felder müssen durch Tabulatoren getrennt sein, jedoch ohne die Überschriften und die Spalte "ii".

Die Standardausgabe:

$ dpkg -l grep
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  grep           2.16-1       amd64        GNU grep, egrep and fgrep

Meine gewünschte Ausgabe:

grep    2.16-1  amd64   GNU grep, egrep and fgrep

Antworten:


18

dpkgist in Ihrem Fall nicht angemessen, bevorzugen Sie dpkg-querystattdessen den Befehl. Mit dpkg-querykönnen Sie den gewünschten Feldtyp (und optional das Trennzeichen) auswählen:

$ dpkg-query -W -f='${binary:Package}\t${Version}\t${Architecture}\t${binary:Summary}\n' grep
grep    2.16-1  amd64   GNU grep, egrep and fgrep

Weitere Optionen (insbesondere die Option) finden Sie in der Manpage dpkg-query.-f --showformat

Als Referenz:

   -W, --show [package-name-pattern...]
          Just like the --list option this will list all packages matching
          the  given  pattern.  However the output can be customized using
          the --showformat option.  The default output  format  gives  one
          line  per  matching package, each line having the name (extended
          with the architecture qualifier for  Multi-Arch  same  packages)
          and installed version of the package, separated by a tab.

   -f, --showformat=format
          This  option  is used to specify the format of the output --show
          will produce. The format is a string that  will  be  output  for
          each package listed.

          In the format string, “\” introduces escapes:

              \n  newline
              \r  carriage return
              \t  tab

          “\” before any other character suppresses any special meaning of
          the following character, which is useful for “\” and “$”.

          Package information can be included by inserting variable refer‐
          ences  to  package  fields  using the syntax “${field[;width]}”.
          Fields are printed right-aligned unless the width is negative in
          which case left alignment will be used. The following fields are
          recognized but they are not necessarily available in the  status
          file  (only internal fields or fields stored in the binary pack‐
          age end up in it):

              Architecture
              Bugs
              Conffiles (internal)
              Config-Version (internal)
              Conflicts
              Breaks
              Depends
              Description
              Enhances
              Essential
              Filename (internal, front-end related)
              Homepage
              Installed-Size
              MD5sum (internal, front-end related)
              MSDOS-Filename (internal, front-end related)
              Maintainer
              Origin
              Package
              Pre-Depends
              Priority
              Provides
              Recommends
              Replaces
              Revision (obsolete)
              Section
              Size (internal, front-end related)
              Source
              Status (internal)
              Suggests
              Tag (usually not in .deb but in repository Packages files)
              Triggers-Awaited (internal)
              Triggers-Pending (internal)
              Version

          The following are virtual fields, generated by  dpkg-query  from
          values from other fields (note that these do not use valid names
          for fields in control files):

              binary:Package
              binary:Summary
              db:Status-Abbrev
              source:Package
              source:Version

          The default format string is  “${binary:Package}\t${Version}\n”.
          Actually,  all  other fields found in the status file (i.e. user
          defined fields) can be requested, too. They will be printed  as-
          is,  though,  no  conversion nor error checking is done on them.
          binary:Package is a special field that will  print  the  package
          name  with an architecture qualifier (like "libc6:amd64") if the
          package has a Multi-Arch field with a value of same, and as such
          its  name could be ambiguous. 
Durch die Nutzung unserer Website bestätigen Sie, dass Sie unsere Cookie-Richtlinie und Datenschutzrichtlinie gelesen und verstanden haben.
Licensed under cc by-sa 3.0 with attribution required.