<!-- 
.. title: sed RULES
.. slug: sed-rules
.. date: 2011-07-14 21:21:52 UTC+01:00 
.. tags: presentations, latex, 
.. link: 
.. description: 
.. type: text 
--> 

[JabRef](http://jabref.sourceforge.net "JabRef") is the current _de facto_ standard for the management of [BibTeX](http://www.bibtex.org "BibTeX") based bibliographies. Since many of my colleagues use JabRef, I had the idea to join the individual bibliographies of those of us working in the same field to form a kind of super-bibliography essentially containing all relevant papers in this field. My companions and me have encountered all kinds of difficulties along this quest (oh holy character encoding!), but we eventuall managed to obtain a functional database free of duplicates and unprintable characters.

As a final polish, I wanted to ensure that proper acronyms and chemical symbols occuring in the references' title would be correctly capitalized after BibTeX/LaTeX compilation, so that, for example, [GaN](http://en.wikipedia.org/wiki/Gallium_nitride "GaN") is not represented as gan \*shudder\*. [BibTeX](http://www.bibtex.org "BibTeX") will do that if the characters in question are enclosed by curly braces, like that: \{GaN\}.

I thought a bit, and came up with the following oneliner:

	sed 's/title = \({[^{]\+}\),/title = {\1},/' -i database.bib,

but that didn't seem to work reliably. Hmm. It took me a minute to realize that [JabRef](http://jabref.sourceforge.net "JabRef") inserts linebreaks at will, causing long titles to span over three or even four lines.

After applying<br />

	sed '/title/N;s/\n\t/ /' -i database.bib

until the database did not change in size anymore, the above oneliner worked to my full satisfaction. 😊

