I’d like to build a bash (or something else) script that when run will search it’s own directory (recursively) for files with the html extension, and change in them all the code between specific tags with the content from another (specific) file.
I’m doing this because I need to have a navigation across all pages but it has small changes in each one that will be taken care of later, so this script would help me to just get the base first, so I can then alter the rest.
I’m specifically looking to do this with a script, locally, not to replace it with javascript or php code in the html.
Based on the great help given by Ben Graham, and a bit more of research, here is the answer to what I was looking for.
You’ll need one file to serve as the script (
replace.sh), another to serve as the replacement (replacementFile), and any other number of files that will have the replacement applied to them.The script.
replace.shAnd that’s it. Some extra points, though.
replacementFileshould have an empty line at the end, or it’ll connect with the next line on the altered file.-i ''is there to provide no backups; if you want them, just place something between the quotes, and it’ll copy the original files with whatever you chose appended.