FVTT-pdf2json-rolltable-cre.../foundrycleaner.sh
Techognito 27d1be4016 Added Bad Lines Remover in foundrycleaner.sh
- set so Auto does line removal
- set so auto does line combining (often needed for when the 100th
  result is on the next line)
2025-08-15 23:36:46 +02:00

106 lines
1.6 KiB
Bash
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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"