Search code examples
awkbibtex

AWK: how to clean bibtex files?


I have a bibtex file (exported from Zotero) and I want to clean it by removing particular fields.

As an example, removing the file field from the following entry:

@inproceedings{sridharan_fast_2008,
    title = {Fast {Rates} for {Regularized} {Objectives}.},
    urldate = {2014-03-26},
    booktitle = {{NIPS}},
    author = {Sridharan, Karthik and Shalev-Shwartz, Shai and Srebro, Nathan},
    year = {2008},
    pages = {1545--1552},
    file = {3400-fast-rates-for-regularized-objectives.pdf:/home/johnros/.zotero/zotero/66g0wvis.default/zotero/storage/6ND67P5F/3400-fast-rates-for-regularized-objectives.pdf:application/pdf}
}

Solution

  • You can do that with grep quite easily:

    grep -v "^\s*file =" bibtext.txt
    

    The trailing comma on the previous record should not be a problem... see here.

    Or, if you are really keen on awk:

    awk '!/file = /' bibtext.txt