102 lines
2.3 KiB
Bash
Executable File
102 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Usage:
|
|
# ./converter.sh input.tsv output.tsv
|
|
#
|
|
# Example:
|
|
# ./converter.sh techniques.tsv techniques-new.tsv
|
|
|
|
if [[ $# -ne 2 ]]; then
|
|
echo "Usage: $0 <input.tsv> <output.tsv>" >&2
|
|
exit 1
|
|
fi
|
|
|
|
input="$1"
|
|
output="$2"
|
|
|
|
awk -F '\t' 'BEGIN {
|
|
OFS = "\t"
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Tier rows
|
|
# ---------------------------------------------------------------------------
|
|
$1 ~ /^Tier / {
|
|
print $0
|
|
next
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Technique header
|
|
#
|
|
# Old:
|
|
# Technique | Niv | Type | Coût | [empty] | Effet | ...
|
|
#
|
|
# New:
|
|
# Technique | Niv | Type | Sang | Jauge | Autre | Effet | ...
|
|
# ---------------------------------------------------------------------------
|
|
$1 == "Technique" {
|
|
printf "%s\t%s\t%s\tSang\tJauge\tAutre", $1, $2, $3
|
|
|
|
# Skip the old Coût column and its following empty column.
|
|
for (i = 6; i <= NF; i++) {
|
|
printf "\t%s", $i
|
|
}
|
|
|
|
printf "\n"
|
|
next
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Empty rows
|
|
# ---------------------------------------------------------------------------
|
|
$0 ~ /^[[:space:]]*$/ {
|
|
print $0
|
|
next
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Technique rows
|
|
# ---------------------------------------------------------------------------
|
|
{
|
|
cost = $4
|
|
|
|
blood = ""
|
|
gauge = ""
|
|
other = ""
|
|
|
|
# Extract blood cost.
|
|
if (match(cost, /[0-9]+🩸/)) {
|
|
blood = substr(cost, RSTART, RLENGTH - length("🩸"))
|
|
}
|
|
|
|
# Extract gauge cost.
|
|
if (match(cost, /[0-9]+⚡/)) {
|
|
gauge = substr(cost, RSTART, RLENGTH - length("⚡"))
|
|
}
|
|
|
|
# Extract any other cost symbols.
|
|
# Currently ◆ is used for "Autre".
|
|
if (match(cost, /[0-9]+◆/)) {
|
|
other = substr(cost, RSTART, RLENGTH - length("◆"))
|
|
}
|
|
|
|
# First three original columns.
|
|
printf "%s\t%s\t%s", $1, $2, $3
|
|
|
|
# New cost columns.
|
|
printf "\t%s\t%s\t%s", blood, gauge, other
|
|
|
|
# Skip old cost ($4) and old empty separator ($5).
|
|
# Everything from Effet onward is preserved.
|
|
for (i = 6; i <= NF; i++) {
|
|
printf "\t%s", $i
|
|
}
|
|
|
|
printf "\n"
|
|
}
|
|
' "$input" > "$output"
|
|
|
|
echo "Converted: $input -> $output"
|