Output from rpm -qa, how to extract only the name of the package?

You can use rpm's --qf queryformat parameter. You give it a format string where you can have tags surrounded by %{}. You can see all the allowed tags with rpm --querytags

I'm guessing you'd want something like:

rpm -qa --qf "%{NAME}\n"

Since you're already pooched, you need to carve off the crap from last year. If it's consistent enough to always be in the stock format, here you go:

#!/usr/bin/python

import sys

for line in sys.stdin:
  if line.startswith('gpg-pubkey-'):
    continue # We don't care about imported keys. G'bye!
  try:
    woarch = line.rsplit('.', 1)[0] # Bye, arch!
    worel = woarch.rsplit('-', 1)[0] # Bye, release!
    wover = worel.rsplit('-', 1)[0] # Bye, version!
  except Exception as e: # Well nuts...
    print ('%s ** %s') % (e, line)
    continue
  print (wover)

Just redirect last year's crap into it and you'll get just the names that matter.


This is far from perfect, but it's worth a try.

$ rpm -qa --qf "%{NAME}\n" > currentlist
$ join -t . -v 1 oldlist currentlist    # show packages in oldlist not in currentlist
$ join -t . -v 2 oldlist currentlist    # show packages in currentlist not in oldlist

This sed command works on all the ones except for the group you labeled "diverse":

sed 's/-[^-]*-[^-]*\.[^.]*\.[^.]*$//'

I believe it works similarly to Ignacio's Python script.

Tags:

Rpm