initial scripts
This commit is contained in:
parent
6b14aa4acd
commit
77e9c9186a
5 changed files with 320 additions and 0 deletions
45
foundryVTTRolltablepdf2json/coulumnsplit.sh
Executable file
45
foundryVTTRolltablepdf2json/coulumnsplit.sh
Executable file
|
|
@ -0,0 +1,45 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Input and output files
|
||||
input_file="columnized.txt"
|
||||
output_file="decolumnized.txt"
|
||||
|
||||
# Process the input file
|
||||
awk '
|
||||
# Function to print the table header
|
||||
function print_table_header(table) {
|
||||
if (table != "") {
|
||||
print ""
|
||||
print "### " table
|
||||
table = ""
|
||||
}
|
||||
}
|
||||
|
||||
/^ *TABLE [0-9]+/ { # Detect table headers
|
||||
table = $0
|
||||
next
|
||||
}
|
||||
|
||||
/^[0-9]+–[0-9]+/ || /^[0-9]+/ { # Match rows starting with "1–6", "7–9", etc.
|
||||
left = substr($0, 1, 50) # Extract left column (first 50 chars)
|
||||
right = substr($0, 51) # Extract right column (remaining chars)
|
||||
|
||||
# Trim whitespace from both sides of each column
|
||||
gsub(/ +$/, "", left)
|
||||
gsub(/^ +/, "", left)
|
||||
gsub(/ +$/, "", right)
|
||||
gsub(/^ +/, "", right)
|
||||
|
||||
# Print the table header if a new row is starting
|
||||
print_table_header(table)
|
||||
|
||||
# Print left column (if it exists) as part of the output
|
||||
if (left != "") {
|
||||
print "- **" left "**: " right
|
||||
} else if (right != "") {
|
||||
print right
|
||||
}
|
||||
}' "$input_file" > "$output_file"
|
||||
|
||||
echo "Reformatted content saved to $output_file"
|
||||
|
||||
89
foundryVTTRolltablepdf2json/foundrycleaner.sh
Executable file
89
foundryVTTRolltablepdf2json/foundrycleaner.sh
Executable file
|
|
@ -0,0 +1,89 @@
|
|||
#!/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"
|
||||
|
||||
77
foundryVTTRolltablepdf2json/foundryrolltable.sh
Executable file
77
foundryVTTRolltablepdf2json/foundryrolltable.sh
Executable file
|
|
@ -0,0 +1,77 @@
|
|||
#!/bin/bash
|
||||
|
||||
inputfile="output.txt"
|
||||
title="Title"
|
||||
description=""
|
||||
inputjson=Template.json
|
||||
outputjson=fvtt-RollTable-$title.json
|
||||
tempjson=temp.json
|
||||
|
||||
#todo: check if empty
|
||||
addItem () {
|
||||
cp "$outputjson" $tempjson
|
||||
local rangemin=$(jq '.results[.results| length-1].range[0]' "$outputjson")
|
||||
local rangemax=$(jq '.results[.results| length-1].range[1]' "$outputjson")
|
||||
#Check what the last range number is and add 1 to that number
|
||||
local newrangemin=$(($rangemin+1))
|
||||
local newrangemax=$(($rangemax+1)) #while this will technically work, this will break of range min and max is not the same
|
||||
# local text= "$1"
|
||||
jq --argjson newrangemin $newrangemin --argjson newrangemax $newrangemax --arg text "${1}" '.results[.results| length] += {"Type": "text", "range": [$newrangemin,$newrangemax],"drawn": false, "text": $text }' "$outputjson" > $tempjson
|
||||
cp $tempjson "$outputjson"
|
||||
rm $tempjson
|
||||
}
|
||||
|
||||
setTitle() {
|
||||
cp "$outputjson" $tempjson
|
||||
jq --arg title "${title}" '.name = $title' "$outputjson" > $tempjson
|
||||
cp $tempjson "$outputjson"
|
||||
rm $tempjson
|
||||
}
|
||||
|
||||
setDescription() {
|
||||
cp "$outputjson" $tempjson
|
||||
jq --arg desc ${description} '.description = $desc' "$outputjson" > $tempjson
|
||||
cp $tempjson "$outputjson"
|
||||
rm $tempjson
|
||||
|
||||
}
|
||||
|
||||
readFile() {
|
||||
echo $1
|
||||
if [ -z "$1" ]; then
|
||||
echo test
|
||||
read -r -p "File location:" fileInput
|
||||
inputfile="$fileInput"
|
||||
else
|
||||
inputfile="$1"
|
||||
fi
|
||||
}
|
||||
|
||||
# todo fix setTitle
|
||||
readTitle() {
|
||||
echo $1
|
||||
if [ -z "$1" ]; then
|
||||
read -r -p "What is the Title of the RollTable? (input as string): " input
|
||||
title="$input"
|
||||
echo $title
|
||||
else
|
||||
title="$1"
|
||||
fi
|
||||
}
|
||||
|
||||
## runtime ##
|
||||
filevar="$1"
|
||||
titlevar="$2"
|
||||
|
||||
echo "Creating a new JSON file for import in FoundrVTT"
|
||||
readFile "$filevar"
|
||||
readTitle "$titlevar"
|
||||
outputjson="fvtt-RollTable-$title.json"
|
||||
cp $inputjson "$outputjson"
|
||||
while read line; do
|
||||
echo "$line"
|
||||
addItem "$line"
|
||||
done < "$inputfile"
|
||||
#todo: make addItem able to read csv with range and text
|
||||
#todo: Check outputfile if item allready exists (prevent duplicate items)
|
||||
setTitle
|
||||
65
foundryVTTRolltablepdf2json/greatSplitter.sh
Executable file
65
foundryVTTRolltablepdf2json/greatSplitter.sh
Executable file
|
|
@ -0,0 +1,65 @@
|
|||
#!/bin/bash
|
||||
outfile=""
|
||||
infile="restofgreatbook.txt"
|
||||
tempfile="restofgreatbook.txt.copy"
|
||||
|
||||
|
||||
split(){
|
||||
outfile=$(head -n 1 $infile).txt
|
||||
headline=$1
|
||||
tailline=$(($1+1))
|
||||
if [[ $1 != "" ]]; then
|
||||
echo $headline
|
||||
echo $tailline
|
||||
clear
|
||||
head -n $headline $infile
|
||||
echo " "
|
||||
# echo " "
|
||||
echo "Lines count (102 for 100 items, 52 for 50 items): "$headline
|
||||
yn=y
|
||||
read -p "Continue with this list? [Y/n]" yn
|
||||
case $yn in
|
||||
[Yy]*)
|
||||
head -n $headline $infile > "$outfile"
|
||||
cp $infile $tempfile
|
||||
tail -n +$tailline $tempfile > $infile
|
||||
;;
|
||||
[Nn]*)
|
||||
echo "split aborted"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "missing number"
|
||||
echo "use 'greatSplitter.sh count | head' to get the next line number "
|
||||
exit 1
|
||||
fi
|
||||
# echo "hello test"
|
||||
# echo $headline
|
||||
# echo $tailline
|
||||
echo $outfile
|
||||
echo $1
|
||||
}
|
||||
|
||||
linecount(){
|
||||
let count=0
|
||||
while read line; do
|
||||
let count=$count+1
|
||||
if [ "$line" = "" ]; then
|
||||
echo $count
|
||||
echo $line
|
||||
fi
|
||||
done < $infile
|
||||
}
|
||||
|
||||
case $1 in
|
||||
|
||||
count)
|
||||
linecount | head -n 1
|
||||
;;
|
||||
|
||||
split)
|
||||
split $(linecount | head -n 1)
|
||||
;;
|
||||
esac
|
||||
|
||||
44
foundryVTTRolltablepdf2json/rolltabletxtfix.sh
Executable file
44
foundryVTTRolltablepdf2json/rolltabletxtfix.sh
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Input and output file names
|
||||
|
||||
input_file="cleanme.txt"
|
||||
output_file="iamclean.txt"
|
||||
|
||||
# Step 1: Remove unwanted characters and blank lines
|
||||
# - Remove form feeds (``)
|
||||
# - Remove empty lines
|
||||
# - Remove lines that are just numbers (like page numbers)
|
||||
sed -e 's/\f//g' -e '/^$/d' -e '/^[0-9]\+$/d' "$input_file" |
|
||||
|
||||
# Step 2: Handle lines where numbering and text are split across two lines
|
||||
awk '
|
||||
# If the line ends with a dot (e.g., "100.") without text, store it for the next line
|
||||
/^[0-9]+\.$/ {
|
||||
line_number = $1
|
||||
next
|
||||
}
|
||||
|
||||
# Combine the stored number with the current line if there is a pending number
|
||||
line_number {
|
||||
$0 = line_number " " $0
|
||||
line_number = ""
|
||||
}
|
||||
|
||||
# Print all valid lines
|
||||
{ print }
|
||||
' |
|
||||
|
||||
# Step 3: Renumber all lines sequentially
|
||||
awk '
|
||||
BEGIN { count = 1 }
|
||||
/^[0-9]+\./ {
|
||||
# Replace the current numbering with sequential numbering
|
||||
sub(/^[0-9]+\./, count ".")
|
||||
count++
|
||||
}
|
||||
{ print }
|
||||
' > "$output_file"
|
||||
|
||||
echo "Cleaned and renumbered list saved to $output_file."
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue