Archive for February, 2009

Generating Bibtex Cite-Keys

Monday, February 2nd, 2009

As I found out recently, Endnote’s bibtex export feature doesn’t really produce bibtex files, but some weird bibtex wannabe format. The biggest problem is that it doesn’t assign cite-keys. If you run into the problem that bib files exported by endnote, you might find this script useful. It simply assigns ascending numbers as cite-keys.

There was also a problem with missing braces in certain publication types, but in my case that was rare enough to be fixed by hand. Vim’s bracket matching and syntax highlighting is quite useful for that kind of thing. Anyway, here is the script. If you find it useful and you would like to extend it to handle the bracket issue, please do get in touch. Of course, the Endnote folks fixing their exporter would also solve the problem…

#!/usr/bin/perl
#
open(MYINPUTFILE, "<$ARGV[0]"); # open for input
my(@lines) = ;
my $counter = 0;
foreach my $line (@lines){
    if ($line =~ /\@article{\n/ | $line =~ /\@incollection{\n/  ){
        $line =~ s/\n/$counter,\n/;
        print $line;
        $counter++;
    }
    else{
        print $line;
    }
}