89 lines
1.4 KiB
Bash
Executable file
89 lines
1.4 KiB
Bash
Executable file
#!/bin/bash
|
||
|
||
# Input and output files
|
||
if [ -z "$2" ]; then
|
||
INPUT_FILE="input.txt"
|
||
else
|
||
INPUT_FILE="$2"
|
||
fi
|
||
if [ -z "$3" ]; then
|
||
OUTPUT_FILE="output.txt"
|
||
else
|
||
OUTPUT_FILE="$3"
|
||
fi
|
||
tempfile=temp.txt
|
||
|
||
# Process the input file
|
||
dice(){
|
||
sed -E 's/([0-9]+[dD][0-9]+)/[[\1]]/g' "$tempfile" > "$OUTPUT_FILE"
|
||
}
|
||
|
||
title(){
|
||
sed -E 's/^([^ -]+.*?)-/<h3>\1<\/h3>-/g' "$tempfile" > "$OUTPUT_FILE"
|
||
}
|
||
|
||
RemoveNumbers() {
|
||
sed -E 's/^[0-9]+\. +//g' "$tempfile" > "$OUTPUT_FILE"
|
||
}
|
||
|
||
ListSort(){
|
||
sort -n "$tempfile" > "$OUTPUT_FILE"
|
||
}
|
||
|
||
lineCombiner(){
|
||
awk '
|
||
/^[0-9]+–[0-9]+/ || /^[0-9]/ {
|
||
if (entry) print entry
|
||
entry = $0
|
||
next
|
||
}
|
||
|
||
/^TABLE/ || /^d12/ || /^-[0-9]-/ {
|
||
if (entry) print entry
|
||
entry = ""
|
||
print
|
||
next
|
||
}
|
||
|
||
{ entry = entry " " $0 }
|
||
|
||
END { if (entry) print entry }
|
||
' "$tempfile" > "$OUTPUT_FILE"
|
||
}
|
||
|
||
|
||
### RUNTIME ###
|
||
|
||
cp "$INPUT_FILE" "$tempfile"
|
||
|
||
case $1 in
|
||
dice)
|
||
dice
|
||
;;
|
||
title)
|
||
title
|
||
;;
|
||
numbers)
|
||
RemoveNumbers
|
||
;;
|
||
sort)
|
||
ListSort
|
||
;;
|
||
lines)
|
||
lineCombiner
|
||
;;
|
||
auto)
|
||
ListSort
|
||
cp "$OUTPUT_FILE" "$tempfile"
|
||
RemoveNumbers
|
||
cp "$OUTPUT_FILE" "$tempfile"
|
||
dice
|
||
;;
|
||
*)
|
||
echo "to use this script either write \"foundrycleaner.sh dice\" or \"foundrycleaner.sh title\" depending if you need [[dice]] or <h3>title</h3>"
|
||
echo "Alternatively use 'foundrycleaner.sh sort'"
|
||
echo "We also have foundrycleaner.sh auto"
|
||
esac
|
||
|
||
echo "Processed file saved as $OUTPUT_FILE"
|
||
|