I have so many static html files (well over a thousand) without Google Analytics code.
my challenge is, not all html files are without Analytics code. this is the folder structure of the files that should have Analytics code added:
user/[user ID]/sites/[site ID]/
there are more than one html files in those folders. I can't simply use sed
on all html files because following files in same "users" folder already have the Analytics js code:
user/[user ID]/editor/index.html
moreover, my html files end with in one line.
How can I add a js code (i.e. Analytics) right before and exclude all theuser/[user ID]/editor/index.html
files from the process?
Use find
and exclude the proper files.
find . -type f -regextype sed -regex '.*users/[0-9]*/sites/[0-9]*/.*html' -exec sed -i 's/pattern/replace/g' "{}" \;
You can always exclude files from that find, say files .*/sites/.*/index.html
:
find . -type f -regextype sed -regex '.*users/[0-9]*/sites/[0-9]*/.*html' -not -name "*index.html" -exec sed -i 's/pattern/replace/g' "{}" \;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With