安装:pip install bibtexparser
(pyhton=3.6可用) 运行下述代码即可(实现.bib参考文献去重)
import bibtexparser
from bibtexparser. bwriter import BibTexWriter
from bibtexparser. bibdatabase import BibDatabase def remove_duplicates ( bib_file_path, output_file_path) : with open ( bib_file_path, 'r' , encoding= 'utf-8' ) as bib_file: bib_database = bibtexparser. load( bib_file) unique_entries = [ ] seen_keys = set ( ) for entry in bib_database. entries: key = entry[ 'ID' ] if key not in seen_keys: seen_keys. add( key) unique_entries. append( entry) new_bib_database = BibDatabase( ) new_bib_database. entries = unique_entries with open ( output_file_path, 'w' , encoding= 'utf-8' ) as output_file: writer = BibTexWriter( ) output_file. write( writer. write( new_bib_database) ) if __name__ == "__main__" : bib_file_path = "refs.bib" output_file_path = "new_refs.bib" remove_duplicates( bib_file_path, output_file_path)