[comp.text] Needed: tool to sort BibTeX files

glr@otc.otca.oz (Gordon Rowell) (05/18/89)

in article <23906@labrea.Stanford.EDU>, finin@PRC.Unisys.COM says:
> 
> 
> I'm looking for a tool that can be used to sort the entries in a
> BibTeX file.  I'd be happy if it sorted by the key, but more
> sophisticated capabilities (i.e. sorting by last name of first author)
> would be just dandy.  Tim
> 
> Organization: Unisys - Paoli Research Center   Paoli, PA
> 

I asked for tools like these a while back and have received them from a
person in Germany who has given me the right to distribute them freely (and
for free!). Rather than replying to lots of individual trans-pacific
requests, would some TeX Archive sites be able to respond and I can send
them once to the archives? People can then collect them locally. The tools 
I have allow easy entry of items into BibTeX databases, sorting of BibTeX
databases and extraction of entries with a given keyword.

For individuals wanting the tools, please wait a week or so (i.e. early
June). If I get some response from archive sites, I shall post their 
addresses here. If not, I will then (if it is the only option) send out 
individual copies. Sending individual copies is time consuming, and slow, 
and sending multiple copies of 30k of source across the pacfic does not
seem too sensible.

			    Gordon Rowell
			    Network R&D
			    |||| OTC ||

			ACSnet:  glr@otc.otca.oz
			  UUCP:  {uunet,mcvax}!otc.otca.oz!glr
			 Snail:  GPO Box 7000, Sydney 2001, Australia
			 Phone:  +61 2 287 5385   FAX: +61 2 287 4490

ralph@nastassia.laas.fr (Ralph P. Sobek) (06/05/89)

I have had to do this in the past.  I defined a function for GNU
emacs.  On a Sun3-160 it took less than 1 minute to sort on the order
4000 references in a 1 Mbyte file.  The key(s) can be changed; for the
moment it's the reference key.  It's set up to be run in batch mode.

Here it is:

(defun sort-BibTeX ()
  (interactive)
  ; A BibTeX record entry here is defined to be:
  ; @name{key,\n...\n}$
  ; For the moment, the key is
  (sort-regexp-fields nil "^@.*{\\(.*\\),\\\n\\(^[^}].*\\\n\\)*}$" "\\1"
                      (point-min) (point-max))
  (set-visited-file-name (concat (buffer-file-name) ".sorted"))
)

Of course, if anyone makes any improvements I would be interested in
receiving them also.

Ralph P. Sobek			  Disclaimer: The above ruminations are my own.
ralph@laas.laas.fr			   Addresses are ordered by importance.
ralph@laas.uucp, or ...!uunet!mcvax!laas!ralph		If all else fails, try:
SOBEK@FRMOP11.BITNET				      sobek@eclair.Berkeley.EDU