[Tex/LaTex] Using Bibtool to sort a bib file by types and keys alphabetically

biblatexbibtoolsorting

I am trying to sort a bib file alphabetically using Bibtool, but I am looking for sorting the entries by types then by keys. For instance, first all the articles, then the books, etc…
With, all the articles sorted alphabetically by keys, then same with the books.

It looks like it should be a command like:

bibtool -s -sort.format={@type $key} -i BiBin.bib -o BiBout.bib 

Thank you all for your help

Romain

Best Answer

Following the example on page 60 of the BibTool manual, the type can be specified with %s($type).

Example:

@misc{def,
    note = {misc entry 1}
}
@article{xyz,
    author = {John Doe},
    title = {On Things},
}
@misc{abc,
    note = {misc entry 2},
}
@article{uvw,
    author = {John Smith},
    title = {Of Things},
}

bibtool -s --sort.format='{%s($type) %s($key)}' -i bibsort.bib -o bibsorted.bib

@Article{     uvw,
  author    = {John Smith},
  title     = {Of Things}
}
@Article{     xyz,
  author    = {John Doe},
  title     = {On Things}
}
@Misc{        abc,
  note      = {misc entry 2}
}
@Misc{        def,
  note      = {misc entry 1}
}

Note that you need single quotes in the terminal command to prevent variable substitution by the terminal.