-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_report_spreadsheets.sh
More file actions
executable file
·47 lines (35 loc) · 1.12 KB
/
convert_report_spreadsheets.sh
File metadata and controls
executable file
·47 lines (35 loc) · 1.12 KB
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
#!/bin/bash
#convert all xlsx files within input directory to html files
#for now this assumes the file names/directory paths do not have spaces in them
#current day
read mon day year < <(date "+%b %_d %Y")
#specify offset if we're not running on the day specified on the worksheet
#read mon day year < <(date -d "-4 days" "+%b %_d %Y")
#properly formatted date
newdate="$mon $day $year"
inputdir=/tmp/report_conversion_input
convertdir=/tmp/report_conversion_output
finaldir=$convertdir/final
if [ ! -d $inputdir ];then
echo "input directory $inputdir doesn't exist, exiting."
exit
fi
if [ -d $convertdir ];then
rm -rf $convertdir
mkdir -p $finaldir
fi
count=0
for xlsx in $inputdir/*.xlsx;do
let count=count+1
mkdir -p $convertdir/$count
#step 1
echo "converting #${count} ($xlsx)"
libreoffice --convert-to html --outdir $convertdir/$count "$xlsx" >/dev/null 2>&1
if [ $? -ne 0 ];then
echo "conversion failed!"
else
#step 2
sed -n "/<em>$newdate<\/em>/,/<!-- \*\*\*\*\*\*\*/p" $convertdir/$count/*.html > $finaldir/$count.html
fi
done
echo "conversions complete, `ls -l $finaldir/*.html|wc -l` result(s) in $finaldir"