forked from chlange/jeopardy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sourcecodeToJeopardyFormat.sh
40 lines (37 loc) · 1.33 KB
/
sourcecodeToJeopardyFormat.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
#!/bin/bash
# Replace control characters with compatible characters
# Version 0.1
# replace new lines with [b] and spaces with
# replace three spaces with html non breaking spaces
# replace two spaces with html non breaking spaces
# replace "<" with html encoded "<"
# replace tab with html encoded spaces
# both parameter defined
if [ $# -eq 2 ]; then
if [ -f $1 ]
then
if [ $2 == "y" ]
then
sed -i -e ':a;N;$!ba;s/\n/[b]/g' -e 's/ /[s][s][s]/g' -e 's/ //g' -e 's/ /[s][s]/g' -e 's/ //g' -e 's/</\</g' -e 's/<//g' -e 's/ /[s][s][s]/g' -e 's/\[b\] /\[b\][s][s][s]/g' $1
else
sed -e ':a;N;$!ba;s/\n/[b]/g' -e 's/ /[s][s][s]/g' -e 's/ //g' -e 's/ /[s][s]/g' -e 's/ //g' -e 's/</\</g' -e 's/<//g' -e 's/ /[s][s][s]/g' -e 's/\[b\] /\[b\][s][s][s]/g' $1
fi
else
echo "File doesnt exist"
fi
# just first parameter defined
# output to console
elif [ $# -eq 1 ]; then
if [ -f $1 ]
then
sed -e ':a;N;$!ba;s/\n/[b]/g' -e 's/ /[s][s][s]/g' -e 's/ //g' -e 's/ /[s][s]/g' -e 's/ //g' -e 's/</\</g' -e 's/<//g' -e 's/ /[s][s][s]/g' -e 's/\[b\] /\[b\][s][s][s]/g' $1
else
echo "File doesnt exist"
fi
else
echo -e "Usage: $0 filename overwriteFile(y/n)"
echo -e ""
echo -e "Parameter"
echo -e " filename: File to convert"
echo -e " overwriteFile: Overwrite file directly (y) or write to console (default)"
fi