How to sort entries in a .bib file with biber

For anyone using a more recent version of biber, the element names have changed slightly. As of biber 2.11, sorting is now sortingtemplate name="tool". This config file works for me:

<config>
  <sortingtemplate name="tool">
    <sort order="1">
      <sortitem order="1">year</sortitem>
    </sort>
    <sort order="2">
      <sortitem order="1">author</sortitem>
    </sort>
    <sort order="3">
      <sortitem order="1">title</sortitem>
    </sort>
  </sortingtemplate>
  <sourcemap>
    <maps datatype="bibtex" map_overwrite="1">
        <map>
            <map_step map_field_set="ABSTRACT" map_null="1"/>
            <map_step map_field_set="FILE" map_null="1"/>
            <map_step map_field_set="keywords" map_null="1"/>
            <map_step map_field_set="mendeley-tags" map_null="1"/>
        </map>
        <map>
            <per_type>ARTICLE</per_type>
            <per_type>BOOK</per_type>
            <per_type>inproceedings</per_type>
            <per_type>incollection</per_type>
            <map_step map_field_set="URL" map_null="1"/>
        </map>    
    </maps>
  </sourcemap>  
</config>

You can run with this command:

biber --tool --output-fieldcase=title --output-indent=4 --output-align --output-file=bibliography.bib --configfile=bib-cleanup.conf --validate-config MyCollection.bib

(--validate-config will assert that your config file passes the Relax NG schema for the config file.)

biber sorting biblatex-sourcemap


Actually with biber 2.3, which is what you are using, it should work with a suitable <sorting> specification in your biber.conf. There was a bug in 2.4, fixed in the 2.5 dev version currently on Sourceforge. As your log says, the default sorting in tool mode is none because people don't always want to change the order of things in their data sources if they are nicely commented etc.

Try something like this in your .conf file (pass the file name with --configfile=<file>

<config>
  <sorting>
    <presort>mm</presort>
    <sort order="1">
      <sortitem order="1">author</sortitem>
    </sort>
    <sort order="2">
      <sortitem order="1">year</sortitem>
    </sort>
  </sorting>
</config>

This would be the full commandline:

biber --tool unsorted.bib --output-file=sorted.bib --configfile=biber-sorting.conf

If the files are not in the current folder, you need to specify the path correctly. If you name the config file biber.conf, biber will use it even without the --configfile parameter as this is the default.


With biber 2.12 I needed to map the journal field to journaltitle. Otherwise the field completely disappeared in the output file. Here's my full config file, based on the one posted by arprice.

<config>
  <sortingtemplate name="tool">
    <sort order="1">
      <sortitem order="1">year</sortitem>
    </sort>
    <sort order="2">
      <sortitem order="1">author</sortitem>
    </sort>
    <sort order="3">
      <sortitem order="1">title</sortitem>
    </sort>
  </sortingtemplate>
  <sourcemap>
    <maps datatype="bibtex" map_overwrite="1">
        <!-- Remove fields -->
        <map>
            <map_step map_field_set="ABSTRACT" map_null="1"/>
            <map_step map_field_set="FILE" map_null="1"/>
            <map_step map_field_set="keywords" map_null="1"/>
            <map_step map_field_set="mendeley-tags" map_null="1"/>
           <map_step map_field_set="issn" map_null="1"/>
        </map>
        <!-- Map journal to journaltitle -->
        <map>
            <map_step map_field_source="journal" map_field_target="journaltitle"/>
        </map>
        <!-- Remove URL for specific types -->
        <map>
            <per_type>ARTICLE</per_type>
            <per_type>BOOK</per_type>
            <per_type>inproceedings</per_type>
            <per_type>incollection</per_type>
            <map_step map_field_set="URL" map_null="1"/>
        </map>
        <!-- Map annote to note -->
        <map>
            <map_step map_field_source="annote" map_field_target="note"/>
        </map>
    </maps>
  </sourcemap>  
</config>

Tags:

Sorting

Biber