I am trying to write a shell script that compiles a latex source. I wish to grab the name of the bibliography file which is contained in a command like:
\bibliography{filename}
I need to save "filename" to a shell variable. My solution to this (in tcsh) is dreadfully embarrassing:
set bioliography=grep -v -E "[[:blank:]]*%[[:blank:]]*" poltheory.tex | grep -E "\\bibliography{[A-Za-z0-9_\.]*}" | tail -1 | sed 's/\\bibliography//' | tr -d { | tr -d } | awk '{print $1}'
This breaks down as:
- do not show commented lines in the latex source
- grab those lines containing a valid bibliography tag
- use only the last one (in case for some reason multiple ones are defined)
- get rid of the curly braces
- set what is left to the shell variable.
Surely there's an elegant way of doing this that I'm overlooking. Can you wow me? I already have a working command, so this is merely in the name of beauty and shell wizardry.