Created
September 27, 2024 11:53
-
-
Save 32teeth/3b787ae1f57d8a4d3ef5efa03d42c155 to your computer and use it in GitHub Desktop.
HTML uppercase to lowercase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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