Last active
October 2, 2017 11:37
-
-
Save micaleel/5878c297edab1ec93fbab458b8e8a613 to your computer and use it in GitHub Desktop.
Lists duplicate BibTex entries in a .bib file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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