Extract rpm package name, version and release using some fancy sed regex

rpm -qa | sed 's/^\(.*\)-\([^-]\{1,\}\)-\([^-]\{1,\}\)$/\1 \2 \3/' | sort | column -t
This command could seem pretty pointless especially when you can get the same result more easily using the rpm builtin queryformat, like: rpm -qa --qf "%{NAME} %{VERSION} %{RELEASE}.%{ARCH}\n" | sort | column -t but nonetheless I've learned that sometimes it can be quite interesting trying to explore alternative ways to accomplish the same task (as Perl folks like to say: There's more than one way to do it!)
Sample Output
[root@docker ~]# rpm -qa | sed 's/^\(.*\)-\([^-]\{1,\}\)-\([^-]\{1,\}\)$/\1 \2 \3/' | sort | column -t
acl                            2.2.51        14.el7.x86_64
aic94xx-firmware               30            6.el7.noarch
alsa-firmware                  1.0.28        2.el7.noarch
alsa-lib                       1.1.6         2.el7.x86_64
alsa-tools-firmware            1.1.0         1.el7.x86_64
atop                           2.3.0         8.el7.x86_64
audit                          2.8.4         4.el7.x86_64
audit-libs                     2.8.4         4.el7.x86_64
audit-libs-python              2.8.4         4.el7.x86_64
authconfig                     6.2.8         30.el7.x86_64
basesystem                     10.0          7.el7.centos.noarch
bash                           4.2.46        31.el7.x86_64
bash-completion                2.1           6.el7.noarch
bc                             1.06.95       13.el7.x86_64
bind-libs                      9.9.4         73.el7_6.x86_64
bind-libs-lite                 9.9.4         73.el7_6.x86_64
bind-license                   9.9.4         73.el7_6.noarch
bind-utils                     9.9.4         73.el7_6.x86_64
binutils                       2.27          34.base.el7.x86_64
[... snip ...]

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: