#!/bin/sh TEMP=$(mktemp -d) IFS=$'\n' cp header.tex "${TEMP}/header.tex" ( echo "\\newcommand{\\doctitle}{Lineare Algebra 1 (Stand: $(date +'%d.%m.%Y'))}"; \ sed 's/\\chead{\\doctitle}//g' header.tex; \ echo "\\title{Komplette Mitschriebe zur Linearen Algebra bei Herr Banagl} \\author{Michael Stapelberg} \\date{Stand: $(date +'%d.%m.%Y')} \\maketitle \\tableofcontents \\clearpage" ) > "${TEMP}/la1.tex" for folder in $(find * -name la1.tex -printf "%h %p\n" | sed 's/^\([0-9]\{2\}\).\([0-9]\{2\}\).\([0-9]\{4\}\)/\3-\2-\1/g' | sort) do IFS=$' ' set -- $folder sed -e 's/\\newcommand{\\doctitle}/\\section/g; s/\\include{header}//g; s/\\end{document}//g; s/\\section\*/\\subsection/g; s/\\subsection\*/\\subsubsection/g' $2 > ${TEMP}/$1.tex echo "\\include{$1}" >> "${TEMP}/la1.tex" done echo "\\end{document}" >> "${TEMP}/la1.tex" cd "${TEMP}" pdflatex la1.tex && pdflatex la1.tex cd - cp "${TEMP}/la1.pdf" . rm -rf "${TEMP}"