I have a bib file with 1,579 entries. This is being read by another (non-LaTeX) system, which I have just recently discovered has opinions about the key: e.g. all - and _ elements are removed. I would like to generate a list of all the bib keys in my file, and would like to avoid writing a home-spun RegEx if at all possible. Is there support within BibTeX for just getting a list of all the keys in a file, so I can target the offending ones?


2 Answers 2


The bibtool program (which is distinct from the bibtools bundle in the other answer) can do what you want. To list all entries whose key includes - you can run

bibtool -i <bibname.bib> -- 'select.by.string{$key "-"}'

If you want to just print the key and and not other fields, you can pipe the output of the previous command to

bibtool -- 'keep.field{$key}'

But if you are using an external tool and that you are open to changing the citation keys so that the external tool will not complain (and you have no requirements to maintain compatibility with an existing TeX document using those citation keys), you can just ask bibtool to normalize the citation keys instead of editing them yourself. See section A.10 in the program manual for details.


As mentioned in a comment the citekeys shell script from the bibtools collection does exactly this. If it is not installed you can download the two files of the script (citekeys and citekeys.bst) from https://ctan.org/tex-archive/biblio/bibtex/utils/bibtools.

Unfortunately the script is written for csh/tcsh with some specific syntax, so it does not work for bash/dash (which I tried) and probably also not with zsh, ksh etc (which I did not try).

Below a simplified version where I stripped the parts that use csh syntax, which are the support for multiple bib files and a cleanup routine to remove extra files. You still need citekeys.bst for this that can be downloaded from the url above.

#!/bin/sh -f
# citekeys - print out all the cite keys in given bib files
# simplified version, adapted from http://mirrors.ctan.org/biblio/bibtex/utils/bibtools/citekeys
# usage: 
#    citekeys file.bib

cat > citekeys.aux <<EOF
bibtex citekeys
rm citekeys.blg

Save as, e.g., citekeyssimple, make executable (chmod +x citekeyssimple) and call with ./citekeyssimple yourbibfile.bib. Afterwards all cite keys from that bib file are listed in the file citekeys.bbl.

Example using biblatex-examples.bib which comes pre-installed with LaTeX distributions and is therefore already in the path:

./citekeyssimple biblatex-examples.bib

Result (first 10 lines shown, the full output is 92 lines):


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .