This repository has been archived by the owner on Apr 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclean_translations
executable file
·50 lines (43 loc) · 1.64 KB
/
clean_translations
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# Cleansing script
clean(){
folder=$(pwd)
echo "Cleaning files in folder: $folder"
for f in $(find * -type f -maxdepth 0 -name "*.html"); do
if [ "$f" != "_DONE" ] && [ -n "${f##*gdoc*}" ] && [ -n "${f##*Icon*}" ] && [ -z "${f##*html*}" ]; then
if grep -q "\[Nid\:" "$f"; then
echo "Correcting /[Nid:/: $f"
perl -pi -w -e 's/\[\[Nid\:([0-9]+)\]\]\./\[\[nid\:$1\]\]/g;' "$f"
fi
# if $(echo "$folder" | grep -qi "german") && grep -q "\ \;" "$f"; then
# echo "Correcting / /: $f"
# perl -pi -w -e 's/\ \;/ /g;' "$f"
# fi
fi
done
}
dup(){
echo "Removing duplicates in folder: $(pwd)"
ls -lrt | while read item; do
hold=$(echo "$item" | awk '{print $9}' | sed 's/\.html//g')
file=$(echo "$item" | awk '{print $9, $10}')
file=$(echo "$file" | xargs) #remove spaces
#if the file isn't the same name as we would change it to and it's not the _DONE folder or a gdoc file or and empty string...
[ "$file" != "${hold}.html" ] && [ "$hold" != "_DONE" ] && [ "$file" != "" ] && [ -n "${file##*gdoc*}" ] && [ -n "${file##*Icon*}" ] && [ -z "${file##*html*}" ] && mv "$file" "${hold}.html" && echo "Duplicate file found: move $file to ${hold}.html"
done
}
task="$@"
if [ "$task" == "dup" ]; then
dup
elif [ "$task" == "text" ]; then
clean
elif [ -z "$task" ]; then
dup
clean
else
echo "Incorrect inputs. Options are:"
echo " clean"
echo " clean all"
echo " clean dup"
echo " clean text"
fi