sortbib
Sort bibliographic database entries
SYNOPSIS
sortbib [ -skey ] [ -tstring ] [ filename ... ]
PARAMETERS
filename ...
One or more bibliographic database files to be sorted. If no filenames are provided, sortbib reads from standard input.
-skey
Specifies the sorting key(s). key is a string of field-identifying characters (e.g., A, T, D for author, title, date). Each character represents a field by which records should be sorted. Multiple keys imply hierarchical sorting. A + before a key indicates ascending order, and a - indicates descending order. For example, -s+A-T sorts by author ascending, then by title descending.
-tstring
Defines the string that marks the start of a bibliographic record. By default, records are separated by blank lines. This option is useful if your records are delimited by a custom string, such as %%.
DESCRIPTION
sortbib is a Unix command-line utility designed to sort bibliographic database files. These files typically conform to the format expected by the refer(1) preprocessor, which is part of the roff and groff text formatting systems. Each bibliographic record is treated as a paragraph, separated by blank lines, and consists of fields marked by a percent sign (%) followed by a key letter (e.g., %A for author, %T for title, %D for date, %J for journal).
The primary purpose of sortbib is to order these records based on specified fields, such as author, title, or date, making it easier to manage and present bibliographies. By default, it sorts records primarily by author (%A), then by title (%T), and finally by date (%D), all in ascending order. Users can customize the sorting criteria using command-line options, allowing for complex multi-field sorting, including both ascending and descending orders. This tool is typically used as a pre-processing step before rendering documents that incorporate bibliographic citations.
CAVEATS
sortbib is a relatively old utility, primarily designed for use with the refer(1) preprocessor and the roff/groff text formatting system. It may not directly support modern bibliography formats like BibTeX, BibLaTeX, or CSL-JSON without prior conversion. Its functionality is specific to the refer format, where records are defined by %key pairs within paragraphs. Users working with contemporary academic writing tools often utilize more specialized bibliography management software.
INPUT FORMAT
sortbib expects input files where each bibliographic record is separated by one or more blank lines. Within each record, fields are denoted by a percent sign (%) followed by a single uppercase letter, e.g., %A for author, %T for title, %D for date. Each field begins on a new line. For example:
%A John Doe
%T An Interesting Paper
%D 2023
%J Journal of Awesome Things
%A Jane Smith
%T Another Great Read
%D 2022
%P 123-145
TEMPORARY FILES
During its operation, sortbib may create temporary files, typically in the /tmp directory, with names similar to /tmp/sortbib*. These files are usually removed automatically upon completion.
HISTORY
sortbib is a legacy Unix utility, originating from the early days of AT&T Unix as part of the troff typesetting suite. Its development was closely tied to the refer preprocessor, which allowed users to embed bibliographic citations directly into text documents formatted with troff or nroff. Over the decades, while troff/roff evolved into groff on Linux systems, sortbib has remained largely unchanged, serving its niche role in the roff ecosystem. Its design reflects the computing environment of its time, emphasizing plain text files and command-line pipeline processing.