#!/bin/bash # From: dotenx.com # description: # Add Google Analytics to all HTML files in a directory. Google Analytics code should be in a file called google-analytics in the same directory as this script. # usage: # ./add-gtag.sh directory # Tested on Mac-zsh directory="$1" if [ -d "$directory" ]; then for file in "$directory"/*.html; do if [[ -f "$file" ]]; then sed -i.bak '//r google-analytics' $file fi done else echo "Directory not found." fi rm $directory/*.bak