Skip to content

Instantly share code, notes, and snippets.

@chapter09
Last active August 29, 2015 14:02
Show Gist options
  • Save chapter09/97b427050f0a74998b08 to your computer and use it in GitHub Desktop.
Save chapter09/97b427050f0a74998b08 to your computer and use it in GitHub Desktop.
compress reference.bib by leaving only one author on the list
import os, sys
import re
in_fd = open('reference.bib', 'r')
out_fd = open('test.bib', 'a')
p = '\{(.*)\}'
for line in in_fd.readlines():
if line.find('author') > -1 or line.find('AUTHOR') > -1:
nl = "\tauthor = {"+ re.search(p, line).group(1).split(" and ")[0]+"{\,}et.al},\n"
out_fd.write(nl)
else:
out_fd.write(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment