3

Reorder .bib file

Hi, I looking into taking a .bib file and reordering the entries so that they end up ordered alphabetically by title. Let me explain what I mean with an example.

Example

Suppose I have the following .bib file:

@book{dummit_abstract_2004,
    location = {Hoboken, {NJ}},
    edition = {3rd ed},
    title = {Abstract algebra},
    isbn = {978-0-471-43334-7},
    publisher = {Wiley},
    author = {Dummit, David Steven and Foote, Richard M.},
    date = {2004},
    keywords = {Abstract, Algebra}
}
@book{herstein_topics_1975,
    location = {Lexington, Mass},
    edition = {2d ed},
    title = {Topics in algebra},
    isbn = {978-0-536-01090-2},
    publisher = {Xerox College Pub},
    author = {Herstein, I. N.},
    date = {1975},
    keywords = {Algebra}
}
@book{burton_first_1970,
    location = {Reading, Mass},
    title = {A first course in rings and ideals},
    isbn = {978-0-201-00731-2},
    series = {Addison-Wesley series in mathematics},
    publisher = {Addison-Wesley Pub. Co},
    author = {Burton, David M.},
    date = {1970},
    keywords = {Ideals (Algebra), Rings (Algebra)}
}

I would like to end up with a file ordered like so:

@book{dummit_abstract_2004,
    location = {Hoboken, {NJ}},
    edition = {3rd ed},
    title = {Abstract algebra},
    isbn = {978-0-471-43334-7},
    publisher = {Wiley},
    author = {Dummit, David Steven and Foote, Richard M.},
    date = {2004},
    keywords = {Abstract, Algebra}
}
@book{burton_first_1970,
    location = {Reading, Mass},
    title = {A first course in rings and ideals},
    isbn = {978-0-201-00731-2},
    series = {Addison-Wesley series in mathematics},
    publisher = {Addison-Wesley Pub. Co},
    author = {Burton, David M.},
    date = {1970},
    keywords = {Ideals (Algebra), Rings (Algebra)}
}
@book{herstein_topics_1975,
    location = {Lexington, Mass},
    edition = {2d ed},
    title = {Topics in algebra},
    isbn = {978-0-536-01090-2},
    publisher = {Xerox College Pub},
    author = {Herstein, I. N.},
    date = {1975},
    keywords = {Algebra}
}

Where the title lines were used to reorder the entries alphabetically.

Biber

I read, in a couple of other questions, that biber's tool mode could be used for something like this provided an appropriate configuration file. I tried running the following command, which has the advantage of better formatting (alignment and indenting)

biber --tool --output-indent=4 --output-align --output-file=bibliography.bib --configfile=bibconfig.conf general.bib

with multiple .conf files that I found in other questions but non gave the result I wanted, that is, the entries were not ordered as in the example.

Summary

Can something like this be done, if so, is biber the best way? Or maybe something like manipulating the file using UNIX tools?

If biber is the best way, then, what would be an appropriate configuration file?

Also, let me know if the bib file in the example is too short, I could provide a longer one for testing if that's required.

4
  • Have a look at bibtool: ctan.org/pkg/bibtool – moewe May 1 '20 at 13:02
  • Also looked at this, although not in depth. Will check the manual and update the question if I find something that works. Thanks! – JLanzuisi May 1 '20 at 13:05
  • Use JabRef, way better. – hesham May 1 '20 at 13:29
  • The biber approach in the answer worked well, but I'll check this out – JLanzuisi May 1 '20 at 13:43
3

With the following bibconfig.conf

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <nosort>
    <option name="settitles" value="\A(A|An|The)\s+"/>
  </nosort>
  <sortingtemplate name="tool">
    <presort>mm</presort>
    <sort order="1">
      <sortitem order="1">title</sortitem>
    </sort>
  </sortingtemplate>
</config>
biber --tool --output-indent=4 --output-align --output-file=bibliography.bib --configfile=bibconfig.conf general.bib

produces

@BOOK{dummit_abstract_2004,
    AUTHOR    = {Dummit, David Steven and Foote, Richard M.},
    LOCATION  = {Hoboken, {NJ}},
    PUBLISHER = {Wiley},
    DATE      = {2004},
    EDITION   = {3rd ed},
    ISBN      = {978-0-471-43334-7},
    KEYWORDS  = {Abstract,Algebra},
    TITLE     = {Abstract algebra},
}

@BOOK{burton_first_1970,
    AUTHOR    = {Burton, David M.},
    LOCATION  = {Reading, Mass},
    PUBLISHER = {Addison-Wesley Pub. Co},
    DATE      = {1970},
    ISBN      = {978-0-201-00731-2},
    KEYWORDS  = {Ideals (Algebra),Rings (Algebra)},
    SERIES    = {Addison-Wesley series in mathematics},
    TITLE     = {A first course in rings and ideals},
}

@BOOK{herstein_topics_1975,
    AUTHOR    = {Herstein, I. N.},
    LOCATION  = {Lexington, Mass},
    PUBLISHER = {Xerox College Pub},
    DATE      = {1975},
    EDITION   = {2d ed},
    ISBN      = {978-0-536-01090-2},
    KEYWORDS  = {Algebra},
    TITLE     = {Topics in algebra},
}

You need to define a sorting template called tool and if you want to skip words such as "A", "An", "The", you need to define a sort exclusion with nosort. More details can be found in the Biber manual.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.