added lines to make directories before redirecting files

Build failed when sed trying to redirect output to non-existent directories. Create those directories before sed needs them.