I have a large bibtex file with many entries where each entry has the general structure
@ARTICLE{AuthorYear,
item = {...},
item = {...},
item = {...},
etc
}
(in some cases ARTICLE
might be a different word e.g. BOOK
)
What I would like to do is write a simple script (preferably just a shell script) to extract entries with given AuthorYear and put those in a new .bib file.
I can imagine that I can recognize the first sentence of an entry by AuthorYear and the last by the single closing }
and perhaps use sed
to extract the entry, but I don't really know how to do this exactly. Can someone tell me how I would achieve this?
It should probably be something like
sed -n "/AuthorYear/,/\}/p" file.bib
But that stops due to the closing }
in the first item of the entry thus giving this output:
@ARTICLE{AuthorYear,
item = {...},
So I need to recognize whether the }
is the only character at a line and only have 'sed' stop reading when this is the case.
sed -n "/AuthorYear/,/\}$/p"
. Note the$
symbol. It works fine, except that it doesn't print the closing}
of a bibitem. Btw, is the use ofsed
necessary?sed
is not necessary at all, I just thought that would be the easiest option. I have figured out a slightly different code:sed -n "/AuthorYear/, /^ *\}/p"
which seems to do exactly what I want, including the closing}
and correcting for spaces if there are any