Skip to content

Instantly share code, notes, and snippets.

@32teeth
Created September 27, 2024 11:53
Show Gist options
  • Save 32teeth/3b787ae1f57d8a4d3ef5efa03d42c155 to your computer and use it in GitHub Desktop.
Save 32teeth/3b787ae1f57d8a4d3ef5efa03d42c155 to your computer and use it in GitHub Desktop.
HTML uppercase to lowercase
#!/bin/bash
# Check if directory is provided
if [ -z "$1" ]; then
echo "Usage: $0 <directory>"
exit 1
fi
DIRECTORY="$1"
# Find all HTML files in the given directory
find "$DIRECTORY" -type f -name "*.html" | while read -r file; do
echo "Processing $file..."
# Use sed to convert HTML tags to lowercase
sed -i.bak -E 's/<\/?[A-Z][^>]*?>/\
$(echo "&" | tr "[:upper:]" "[:lower:]")/g' "$file"
# Handle self-closing tags like <IMG />
sed -i.bak -E 's/<([a-z]+)([^>]*)\/>/\
<\1\2 \/>/g' "$file"
# Cleanup backup files created by sed
rm "${file}.bak"
done
echo "All HTML files processed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment