Skip to content

Instantly share code, notes, and snippets.

@micaleel
Last active October 2, 2017 11:37
Show Gist options
  • Save micaleel/5878c297edab1ec93fbab458b8e8a613 to your computer and use it in GitHub Desktop.
Save micaleel/5878c297edab1ec93fbab458b8e8a613 to your computer and use it in GitHub Desktop.
Lists duplicate BibTex entries in a .bib file
"""Find duplicate BitTex entries."""
import sys
import os
from collections import Counter
from pprint import pprint
def extract_id(line):
x = line.index('{')
y = line.index(',')
return line[x+1: y].strip()
def main():
filepath = sys.argv[1]
assert os.path.exists(filepath)
with open(filepath, 'r') as fp:
lines = [extract_id(line) for line in fp.readlines() if line.startswith('@')]
counts = Counter(lines)
for k,v in counts.items():
if v > 1:
print('{:>35}: {}'.format(k, v))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment