Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The output format from the command rpm -qa looks like the following:


Can anyone tell me how to reliably remove the version, release, and arch part so that I end up with


I would rather avoid trying to construct a regular expression for sed, because I expect it to be complicated in order to support names like super-3d-editor-0.1-1.fc14.x86_64 or similar. I am sure I am not the first person wanting such filtering, therefore I ask here to check if there already exists some solution.

Update: The "or similar" note above implies some knowledge about what rpm package names looks like. Most of them are "nice looking" like the ones presented above, but there are also entries with more diverse numbering schemes:


Also note that there exists packages where a version number is part of the name like


and there are even a few where the release/arch is missing (these might be hard to handle, and I can accept failure to handle these)


That is why I asked for a reliable way to do this; I knew that creating an approximate sed regex would be possible but it was bound to fail to handle many lines.

(I know that it is possible to format the output from rpm with --queryformat, however that will not be of help to me because I want to compare which packages I have installed today by comparing with a rpm -qa listing that was generated a year ago.)

share|improve this question
You mean the version, release, and the arch. – Ignacio Vazquez-Abrams Dec 17 '10 at 21:56
Yes, I do. I will update the question. – hlovdal Dec 17 '10 at 22:09
up vote 4 down vote accepted

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:


import sys

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

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

share|improve this answer
Thank you, this worked perfectly. – hlovdal Dec 18 '10 at 12:56

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.

share|improve this answer
Although not explicit stated in the answer, the oldlist file is created with the given sed command. – hlovdal Dec 18 '10 at 12:48
Thank you. Although not perfect as you say (I see that it is a tiny bit too happy to remove parts so for instance fedora-package-config-smart ends up as just fedora-package-config), it works way better than the sed regex I came up with, and together with Ignacio Vazquez-Abrams' answer I can compare and merge (using kdiff3). – hlovdal Dec 18 '10 at 12:49
@hlovdal: Actually, I intended for the oldlist to be as originally created, without being further processed. – Dennis Williamson Dec 18 '10 at 14:51

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"
share|improve this answer
This will not help me as I point out at the end of the question. – hlovdal Dec 17 '10 at 23:58
If you are the one to dock the answers (myself and another) it's sort of impolite to downvote based on a spec that we didn't see (not sure if it was added after i answered). This is a simple sed request then. something like sed 's/-[0-9].*\.(x86|x86_64)$//' would serve as a starting point. – Rich Homolka Dec 18 '10 at 0:24
The note about formatting the output from rpm was there from the very start (I only added "with --queryformat" later), you can view the history to check, – hlovdal Dec 18 '10 at 1:29
Maybe it is impolite to downvote, but for a "please do not answer X" question I think it is proper policy to downvote (pure) X answers (also consider that I might find it sort of impolite to answer the with the exact thing I said I did not want). – hlovdal Dec 18 '10 at 1:30
The regex will not be that simple (and I think regex is the wrong tool for this). I am currently using 's/-[0-9]\+(\.[0-9_a-z]\+)*-[0-9]\+(\.[0-9a-z])*.[^.]\+.[0-9]\+.[^.]\+$//', but there are many lines this RE fails to match and update. – hlovdal Dec 18 '10 at 1:30

rpm is a very flexible command with a bunch of useful options.

For, instance you may want to show the date of the intallation of each package using:

rpm -qa --queryformat '%{NAME} %{INSTALLTIME:date}\n'

(--qf is the short form of --queryformat)

Have a look at:

share|improve this answer
This will not help me as I point out at the end of the question. – hlovdal Dec 17 '10 at 23:58

Not sure why you think --queryformat won't help you... why not do as one of the previous answers suggests and use it to split out the version and architecture from the name? That way, you can output the rpm -qa listing in CSV or tab-separated format for later processing.

share|improve this answer
The point is that I already have some existing files made with rpm -qa a long time ago, and without a time machine I cannot go back and recreate those files with --queryformat. That is why. – hlovdal Dec 18 '10 at 0:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .