variable sub doesn't work in '
move the sed -i into the 'if file exists' sections