Skip to content

Instantly share code, notes, and snippets.

@tobin
Created September 28, 2011 03:23
Show Gist options
  • Select an option

  • Save tobin/1246914 to your computer and use it in GitHub Desktop.

Select an option

Save tobin/1246914 to your computer and use it in GitHub Desktop.
Truncate authors list in citeulike.org-generated BibTeX file
#!/usr/bin/perl -w
# Read a BibTex file generated by citeulike.org and truncate any author lists
# that contain too many authors.
#
# Tobin Fricke, 2011-09-27
use strict;
my $max_authors = 10;
while (<>) {
my $line = $_;
if ($line =~ /^ author = {(.*)},$/) {
my @authors = split / and /, $1;
if (scalar(@authors) > $max_authors) {
# only give one author, "and others".
print " author = {" . $authors[0] . " and others},\n";
} else {
# authors list has acceptable number of authors
print $line;
}
} else {
# this line does not define an author list
print $line;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment