blob: 49417f59b9b66ed5ee83b5f7de130fea9ed36d57 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#!/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 "p>any amount of characters</p" from current file
# remove the "p>" and "</p" from result
# make everything that starts with "<" blank
# take all lines that aren't blank
description=$(egrep -o "p>(.+)<\/p" $file | sed "s/p>\|<\/p//g" | sed "s/<.*//g" | grep .)
# Get the first 200 characters only when it's longer than 200 characters
if [ ${#description} -gt 200 ]; then
description="${description::200}..."
fi
# Escape all non-acceptable characters (thanks https://www.unix.com/302989284-post3.html)
description=$(echo $description | sed 's/[^a-zA-Z 0-9]/\\&/g')
# Replace all "[DESCRIPTION]" text in current file with what we selected (inside description)
sed -i "s/\[DESCRIPTION\]/$description/g" $file
done
|