I have a directory of let's call them template files. They have one value in them that needs to be substituted. I wanted a pristine folder with a 'keyword' in the substitution place in each file. I wanted to substitute the word and output all files to a new folder with files named the same as the input. The command that I found here is:
find . -name '*.sql' -i -exec sed -e 's/TEXTTOSUBSTITUTE/SUBSTITUTIONTEXT/g' {} \;
How can I get this command to output files to another directory and leave the originals unchanged? thank you so much for your help! I want the original files to remain unchanged. the folder is called Templates and the folder in the same directory as the directory Templates is called Usefiles. The template files act as the base files and so should not change. I guess I could use the suggestion above, but do 2 separate find commands, one to copy and the other to sed in the new directory UPDATE>>>> I've been trying the suggestions, but the sed doesn't seem to work. The copy works, but the sed is a variable and is coming out blank in the script. Here is my current, and thanks again!! :
#!/bin/bash
echo "Enter Year i.e. 2020"
read -p reportyear
echo "Enter Month i.e. 04"
read -p reportmonth
SUBSTITUTIONTEXT=$reportyear/$reportmonth
find MOT/ -name '*.sql' -exec sh -c 'for f; do
echo cp -v "$f" MOU/ && echo sed -ie "s/TEXTTOSUBSTITUTE/$SUBSTITUTIONTEXT/g" MOU/"${f##*/}"
done' _ {} +
FINAL UPDATE Thanks to you guys, a working solution:
echo "Enter Year i.e. 2020"
read reportyear
echo "Enter Month i.e. 04"
read reportmonth
SUBSTITUTIONTEXT=$reportyear\/$reportmonth
cd /to/relevant/files
find MOT/ -name '*.sql' -exec sh -c 'for f; do
cp -v "$f" MOU/ && sed -i 's@SUBSTITUTIONYEARMONTH@"$SUBSTITUTIONTEXT"@' MOU/"${f##*/}"
done' _ {} + > /dev/null 2>&1