-
Notifications
You must be signed in to change notification settings - Fork 0
/
stripWordComments.sh
66 lines (60 loc) · 1.69 KB
/
stripWordComments.sh
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# A script to replace the name and/or date of comments in a Microsoft Word .docx file
# Use -f 'file name' -a 'new author name' and -d to remove date.
usage="$(basename "$0") [-h] [-f 'filename' -a 'authorname' -d]
-- A script to replace the name and/or date of comments in a Microsoft Word .docx file
where:
-h show this help text
-f specify the name .docx file
-a specify the new author name
-d specify if date of comments should be removed (ignored)"
mkdir ./temp;
f_present=0;
while getopts "f::a:d" opt; do
case $opt in
h)
echo "$usage" >&2
exit
;;
f)
FILENAME=$OPTARG
unzip $FILENAME -d ./temp
echo "Copied and extracted the file." >&2
f_present=1;
;;
a)
if [ $f_present -eq 0 ]; then
rm -r ./temp;
echo "ERROR: Missing the -f argument." >&2
echo "$usage" >&2
exit 1
fi
AUTHOR=$OPTARG
sed -i -e 's/w:author="Author"/w:author="'"$AUTHOR"'"/g' ./temp/word/comments.xml
sed -i -e 's/w:author="Author"/w:author="'"$AUTHOR"'"/g' ./temp/word/document.xml
echo "Replaced the author name." >&2
;;
d)
if [ $f_present -eq 0 ]; then
rm -r ./temp;
echo "ERROR: Missing the -f argument." >&2
echo "$usage" >&2
exit 1
fi
sed -i -e 's/w:date/w:ignore/g' ./temp/word/comments.xml
sed -i -e 's/w:date/w:ignore/g' ./temp/word/document.xml
echo "Removed the date."
;;
\?) printf "illegal option: %s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
esac
done
FILENAMENEW="${FILENAME%.docx}_new.docx"
echo $FILENAMENEW;
cd temp;
zip -r ../$FILENAMENEW *;
cd ..;
rm -r ./temp;
exit 0;