blob: bf739ffa7e76b873a08c473f12e08dd6f303113c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#!/bin/bash
if [ -z "$1" ]; then
echo First parameter must be a path
exit
fi
# Loop through all HTML files in given directory
for file in $(find "$1" -type f -name "*.html"); do
# Get text that matches "h1>any amount of characters</h1" from current file
# remove the "h1>" and "</h1" from result
title=$(egrep -o "h1(.+)>(.+)<\/h1" $file | sed "s/h1[^>]\+>\|<\/h1//g")
# Escape all non-acceptable characters (thanks https://www.unix.com/302989284-post3.html)
title=$(echo $title | sed 's/[^a-zA-Z 0-9]/\\&/g')
# Replace all "[TITLE]" text in current file with what we selected (inside title)
sed -i "s/\[TITLE\]/$title/g" $file
done
|