Posts Tagged ‘latex’

Extracting citations from a BibTex file using Linux terminal

I had a big (around 40 entries) BibTex file with the references of some papers I studied and I wanted to extract the citations in the format used for citing in Latex (\cite{AuthorYear}). Just today I read some tutorials about awk, so I thought “Let’s use it!!”.

An example BibTex file:

author = {Kotselidis, Christos and Lujan, Mikel and Ansari, Mohammad and Malakasis,
    Konstantinos and Kahn, Behram and Kirkham, Chris and Watson, Ian},
doi = {10.1109/IPDPS.2010.5470460},
isbn = {978-1-4244-6442-5},
journal = {2010 IEEE International Symposium on Parallel \&
    Distributed Processing (IPDPS)},
pages = {1--12},
publisher = {Ieee},
title = {{Clustering JVMs with software transactional memory support}},
url = {},
year = {2010}
author = {Zhang, Bo},
keywords = {cache-coherence,contention manager,distributed transactional memory},
title = {{On the Design of Contention Managers and Cache-Coherence Protocols for
    Distributed Transactional Memory}},
year = {2009}


awk 'BEGIN{FS="[{,]"} /@/ {print "\\cite{"$2"}"}' filename.bib


In order to save the output in a file named cites.txt:

awk 'BEGIN{FS="[{,]"} /@/ {print "\\cite{"$2"}"}' filename.bib > cites.txt

Hint: Use “>>” if you want to append the output. Single > creates a new file (if not existing), or empties the existing one and then appends the content..

If you want to know my “implementation” process, continue reading 😉
Read the rest of this entry »