16

I have a bibliography on a subject (don't matter what subject it is, there is about 20 different files and about 1000 records). I need to convert it into csv (or any other table format which can be opened in Excel/LibreOffice Calc etc.)

Can anyone name a tool for this?

5 Answers 5

20

Open the .bib-files in Jabref and export them as OpenOffice .csv-files. You find the option under the menu File, Export

Jabref_export

Since you can run Jabreffrom the program's home page, you don't have to install it. You need Java, though.

1
  • Thanks. Jabref is cool thing. It's a bit strange but still cool.
    – Georg
    Aug 31, 2012 at 5:50
13

Best bet would be a scripting language, e.g. Python. I don't know if you are a programmer, but making a script taking each entry and converting them should be pretty quick (provided typing python script_file.py in the prompt doesn't scare you!). Python is also installed by default on most Unix OSes.

Here's a basic python script which accesses a few fields:

from pybtex.database.input import bibtex

#open a bibtex file
parser = bibtex.Parser()
bibdata = parser.parse_file("myrefs.bib")

#loop through the individual references
for bib_id in bibdata.entries:
    b = bibdata.entries[bib_id].fields
    try:
        # change these lines to create a SQL insert
        print(b["title"])
        print(b["journal"])
        print(b["year"])
        #deal with multiple authors
        for author in bibdata.entries[bib_id].persons["author"]:
            print(author.first(), author.last())
    # field may not exist for a reference
    except(KeyError):
        continue

You can adapt it to your needs and save desired fields to a .csv file.

3
  • I already thought about it. But I'm looking for a existing tool for it. and, actually, I don't know any scripting language
    – Georg
    Aug 30, 2012 at 18:02
  • Best part about python, Everything is already done. Thanks for the nice snippet
    – DJK
    Nov 27, 2017 at 21:15
  • 1
    I like this solution. As an improvement I would suggest using b.get(field), since this avoids the KeyError exception. Oct 10, 2018 at 11:54
5

A python version using bibtexparser bibtexparser and pandas

with open('ref.bib') as bibtex_file:
  bib_database = bibtexparser.load(bibtex_file)
df = pd.DataFrame(bib_database.entries)
df.to_csv('ref.csv', index=False)

And a minimal working example:

import bibtexparser
import pandas as pd

bibtex = """@article{ einstein1935can,
            title={Can quantum-mechanical description of physical reality be considered complete?},
            author={Einstein, Albert and Podolsky, Boris and Rosen, Nathan},
            journal={Physical review},
            volume={47},number={10},
            pages={777},
            year={1935},
            publisher={APS}}
            @inproceedings{sharma2017daniel,
            title={DANIEL: A deep architecture for automatic analysis and retrieval of building floor plans},
            author={Sharma, Divya and Gupta, Nitin and Chattopadhyay, Chiranjoy and Mehta, Sameep},
            booktitle={2017 14th IAPR International Conference on Document Analysis and Recognition (ICDAR)},
            volume={1},pages={420--425},year={2017},organization={IEEE}}"""

with open('ref.bib', 'w') as bibfile:
  bibfile.write(bibtex)
with open('ref.bib') as bibtex_file:
  bib_database = bibtexparser.load(bibtex_file)
df = pd.DataFrame(bib_database.entries)
df.to_csv('ref.csv', index=False)
2

It is also possible to do if you use a reference manager as Zotero. Then you can import a bibtex file. It will result in its own folder, and then you can export it to whatever format you want.

Just another solution :)

2

Another option in R is to use the package bib2df:

# Install bib2df
install.packages('bib2df')

# Load bib2df
library(bib2df)

# Set path to .bib
# (Example data)
path <- system.file("extdata", "LiteratureOnCommonKnowledgeInGameTheory.bib", package = "bib2df")

# (Alternatively, your own file)
# path <- 'refs.bib'

# Read .bib as a data.frame
df <- bib2df(path)

# Parse the author and editor columns (list columns cannot be saved directly in a csv)
df$AUTHOR <- vapply(df$AUTHOR, paste, collapse = ' and ', '')
df$EDITOR <- vapply(df$EDITOR, paste, collapse = ' and ', '')

# Export to csv
write.csv(df, 'refs.csv')

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .