- set so Auto does line removal - set so auto does line combining (often needed for when the 100th result is on the next line)
106 lines
1.6 KiB
Bash
Executable file
106 lines
1.6 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"
|
||
}
|
||
|
||
badLineRemover() {
|
||
grep -Ev "[0-9] {1,}" "$tempfile" > "$OUTPUT_FILE"
|
||
}
|
||
|
||
outToTemp() {
|
||
cp "$OUTPUT_FILE" "$tempfile"
|
||
}
|
||
|
||
|
||
|
||
### RUNTIME ###
|
||
|
||
cp "$INPUT_FILE" "$tempfile"
|
||
touch $tempfile
|
||
|
||
case $1 in
|
||
dice)
|
||
dice
|
||
;;
|
||
title)
|
||
title
|
||
;;
|
||
numbers)
|
||
RemoveNumbers
|
||
;;
|
||
sort)
|
||
ListSort
|
||
;;
|
||
lines)
|
||
lineCombiner
|
||
;;
|
||
badlinesrm)
|
||
badLineRemover
|
||
;;
|
||
auto)
|
||
lineCombiner
|
||
outToTemp
|
||
badLineRemover
|
||
outToTemp
|
||
ListSort
|
||
outToTemp
|
||
RemoveNumbers
|
||
outToTemp
|
||
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"
|
||
|