x56-layout/generate.sh

38 lines
639 B
Bash
Raw Normal View History

2024-05-31 12:07:31 +00:00
#/usr/bin/env sh
set -eo pipefail
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <mapping.csv> <image.svg>"
exit 1
fi
MAPPING_FILE=$1
IMAGE_FILE=$2
if [ ! -f "$MAPPING_FILE" ]; then
echo "$MAPPING_FILE not found!"
exit 1
fi
if [ ! -f "$IMAGE_FILE" ]; then
echo "$IMAGE_FILE not found!"
exit 1
fi
2024-05-31 12:21:51 +00:00
awk -F, '
NR==FNR {
map[$1] = $2
next
}
{
line = $0
for (key in map) {
# Escape special characters in the key
gsub_key = key
gsub_key = gensub(/[$.*+?^{}|()[\]\\]/, "\\\\\\0", "g", gsub_key)
gsub(gsub_key, map[key], line)
}
print line
}' $MAPPING_FILE $IMAGE_FILE