Since I was here in any case, I decided to add a --for-machine option to calibredb list that makes it easier to parse the output.
And here's a one liner (in python because I hate sh) that demonstrates how to get a list of all ids and formats for ever id in the library
Code:
calibredb list --for-machine -f formats | python2 -c "import sys; print '\n\n'.join('id:%s formats:%r' % (r.partition(chr(29))[0], r.partition(chr(29))[-1].split(chr(28))) for r in sys.stdin.read().split(chr(30)) if r.strip())"
And the help of --for-machine
Code:
--for-machine Generate output that is more suitable for machine
parsing. Book entries are separates using the ASCII
Record Separator character (30), individual fields in
an entry using the Group Separator (29) and individual
filenames using the File Separator (28)