You are viewing dontdothat

Quick package search in Debian/Ubuntu/etc.

« previous entry | next entry »
Dec. 13th, 2008 | 01:23 pm

This is a one-liner that I've found useful for searching Tag: fields in Debian's package lists. For instance, I might want to know about all the packages available that have to do with Ruby. I'll assume that any mention of the string 'ruby' in the Tag: field of a package warrants its selection.

egrep -hr '^(Package:|Tag:.+ruby)' /var/lib/apt/lists|grep -B1 ^Tag|grep ^Package|cut -d\ -f2-|tr \\n \||xargs -I{} apt-cache --names-only search ^\({}\)\$|sort|less

The first egrep does a recursive search through the package list that apt maintains. The -h flag suppresses printing the filename. The regex selects every occurrence of lines beginning with "Package:" and lines beginning with "Tag:" and containing the string "ruby". In the next grep, packages without a matching Tag: line are discarded. Another grep to clean that up, then cut out everything but the package name, tr newlines into a literal pipe, and pass the now-single line to xargs. That part is a little ugly, because apt-cache wants a regular expression and it's trying too hard for this purpose when all that is needed is an exact match of the package name. Insert an echo before the apt-cache invocation to see what it's doing. It's not a particularly elegant solution, and it works.


edit -- the original version still had echo before apt-cache, which wouldn't have been useful. Fixed

Tags: , ,

Link | Leave a comment | Share

Comments {0}