Topic: Print contents of specific apt repos

Cadged this from someone else and tweaked it a bit.

#!/bin/bash
# ~/bin/searchrepo.sh

cd /var/lib/apt/lists/
cat *$1* | grep "^Package: " | sed 's/^Package: //' | sort -u

Usage - "searchrepo.sh string" 
Example - "searchrepo.sh multimedia"  -  prints all packages contained in repos with string "multimedia" in their name.

Useful with output piped thru grep to search for specific packages.

Last edited by spoovy (2011-01-24 01:10:50)

Re: Print contents of specific apt repos

Is this better than using Synaptic or apt-cache to search for packages?

Note: ** Please read before posting **

BTW if you wish to contact me, send me an e-mail instead of a PM.

Re: Print contents of specific apt repos

I never found a way with aptitude, so I use this.  There might be a way with apt-cache i dunno i never thought to look to be honest.  Never use synaptic.


Is there a way with apt-cache?

Last edited by spoovy (2011-01-24 00:34:37)

Re: Print contents of specific apt repos

sudo apt-cache search multimedia

laptop: asus zenbook UX31 [debian wheezy, kernel 3.3.0-rc7-custom]
tablet: acer iconia a500 [honeycomb]
home: C2D E8500, 4GB RAM, 74GB Raptor HDD + 2.5TB in various HDD [debian squeeze, liquorix kernel]

Re: Print contents of specific apt repos

I don't think you need the sudo for searching.

Note: ** Please read before posting **

BTW if you wish to contact me, send me an e-mail instead of a PM.

Re: Print contents of specific apt repos

pitje wrote:

sudo apt-cache search multimedia

That just searches for packages containing the string "multimedia", in all enabled repos.  As in, it returns packages from all enabled repos.

My script returns only results from the specified repo.

Last edited by spoovy (2011-01-24 00:47:32)

Re: Print contents of specific apt repos

@spoovy - using your script how or where would you specify the repo you wanted to search?

Note: ** Please read before posting **

BTW if you wish to contact me, send me an e-mail instead of a PM.

Re: Print contents of specific apt repos

It's explained in the OP.  The example searches the debian multimedia repo, as it's the only repo in my sources.list with "multimedia" in the title.

You could use it to search any repo by specifying any string unique to that repo.  I run debian with the statler repo added post install, so I also use it to see what's available in the statler repo with "searchrepo.sh statler".

Re: Print contents of specific apt repos

Ok I understand now. For some reason I was thinking the string was the package name not repo name.

Note: ** Please read before posting **

BTW if you wish to contact me, send me an e-mail instead of a PM.

Re: Print contents of specific apt repos

I tried to get it to work passing a second argument to grep but I haven't figured it yet.  Any ideas?

It would need to return all results in the absence of a second argument, or only those results matching the second argument if one is present.

| grep "$2"  doesn't work.