sed RULES

JabRef is the current de facto standard for the management of 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 is not represented as gan *shudder*. 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 inserts linebreaks at will, causing long titles to span over three or even four lines.

After applying

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. 😊