#!/bin/bash
#
#  $1 name of odt file
#	
#  list file with Anrede etc. 
#
#	XYZ  term to be replaced 
#
# ii temp directory to extract odt file 
#  
# the script creates odt and pdf files witht the term XYZ replaced by the line in "list" and saves the files 
# under "line" (no spaces). 


rm -rf ii/*

unzip -d ii "$1"

cp ii/content.xml .

while read line
do
	cp content.xml ii/.
	
	pushd ii

	sed -ri 's|XYZ|'"$line"'|' content.xml

	file="${1// /}-${line// /}.odt"
	
	zip -r "../$file" *

	popd 

	libreoffice --headless --convert-to pdf "$file"

done < list


	