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

abrt-1.1.14-1.fc14.x86_64 abrt-addon-ccpp-1.1.14-1.fc14.x86_64 abrt-addon-kerneloops-1.1.14-1.fc14.x86_64 abrt-addon-python-1.1.14-1.fc14.x86_64 abrt-desktop-1.1.14-1.fc14.x86_64 abrt-gui-1.1.14-1.fc14.x86_64 abrt-libs-1.1.14-1.fc14.x86_64 abrt-plugin-bugzilla-1.1.14-1.fc14.x86_64 abrt-plugin-logger-1.1.14-1.fc14.x86_64 abrt-plugin-runapp-1.1.14-1.fc14.x86_64 

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

abrt abrt-addon-ccpp abrt-addon-kerneloops abrt-addon-python abrt-desktop abrt-gui abrt-libs abrt-plugin-bugzilla abrt-plugin-logger abrt-plugin-runapp 

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:

fxload-2002_04_11-9.fc12.x86_64 GitPython-0.2.0-0.3.beta1.fc14.noarch ModemManager-0.4-4.git20100720.fc14.x86_64 python-peak-rules-0.5a1.dev-12.a1.dev.20100803svn2646.fc14.noarch pytz-2010h-3.fc14.noarch 

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

java-1.5.0-gcj-1.5.0.0-34.fc14.x86_64 java-1.6.0-openjdk-1.6.0.0-49.1.9.3.fc14.x86_64 java-1.6.0-openjdk-devel-1.6.0.0-49.1.9.3.fc14.x86_64 

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)

bouml-doc-4.3.2-3.noarch fedora-release-14-1.noarch glibc-2.12.90-21.i686 basesystem-10.0-3.noarch ivtv-firmware-20080701-20.noarch gpg-pubkey-97a1071f-4c49d6fe 

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.)

2

6 Answers

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.

0

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" 
5

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.

3

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

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

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

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

Have a look at:

1

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.

1

I like the above which is perfect and by far the simplest but I wish to get a list and install them on another machine so I do this:

rpm -qa --qf "%{NAME} " >installed-rpms.txt 

then I do this on the next machine:

yum -y install $(cat installed-rpms.txt) 

I have to add -y because I really want to do this a lot and I am sure the rpm list is what I want.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy