I'm searching for a way to edit/re-order the entries in the .bib file to match the ordering defined for the bibliography. There are several questions here about ordering the bibliography, but I haven't found anything regarding ordering the .bib file itself…perhaps because it isn't possible! For instance, Sorting bibliography according to the order in .bib file is the opposite of what I'm looking for. I want to sort the .bib file according to the order in the bibliography.
The reason is because I have several .bib files organized by topic, each topic file organized by when I read the source. It would save me quite a bit of time to have the entries organized so that, for instance, I could delete an entire stretch of one author's sources instead of searching for them one by one.
%LuaLaTeX
\documentclass{report}
\usepackage[authordate,backend=biber,sorting=nyt]{biblatex-chicago}
\begin{filecontents}{bib.bib}
@book{bcd,
author = {Mike Man},
title = {Title},
year = {2016},
publisher = {Books},
}
@book{cde,
author = {Bill Ban},
title = {Name},
year = {2009},
publisher = {Publisher},
}
@book{abc,
author = {Bill Ban},
title = {Something},
year = {2014},
publisher = {Somewhere},
}
\end{filecontents}
\addbibresource{bib.bib}
\nocite{*}
\begin{document}
Text.
\printbibliography
\end{document}
Ideally there could be a way to reorder bib.bib such that it matches the defined ordering in the bibliography (thus, authordate,sorting=nyt
). In this case, the intended ordering should be cde
, abc
, bcd
.
Best Answer
This is possible with
biber
's tool mode. Suppose your .bib is "test.bib" and you have the following in "test.conf" (this is just the config file version of the "nyt" sorting scheme - see the biblatex/biber PDF docs about this).Then simply run this command:
and your sorted .bib will be in
test_bibertool.bib
.biber
uses a default config file in tool mode which you can find by running:you can then copy this file and edit it to your needs. You can do many things to your .bib files with tool mode such as reformatting, sorting, changing the data using sourcemaps, materialising inheritance rules etc. See the
biber
PDF documentation.The
biber
PDF manual (currently section 3.1.7) has details of the format of the sorting specification accepted in the config file.