From f077bd40b556369e77bbefbb6647fa4712ba2cd9 Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Fri, 31 May 2024 14:21:51 +0200 Subject: [PATCH] fixed generate script --- generate.sh | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/generate.sh b/generate.sh index 39f94de..492b81c 100755 --- a/generate.sh +++ b/generate.sh @@ -20,12 +20,18 @@ if [ ! -f "$IMAGE_FILE" ]; then exit 1 fi -# awk -F, 'NR==FNR {map[$1] = $2; next} {for (key in map) gsub("\\b" key "\\b", map[key]); print}' $MAPPING_FILE $IMAGE_FILE - - -awk -F, 'NR==FNR {map[$1] = $2; next} END {for (key in map) print key, "=>", map[key]}' $MAPPING_FILE - - -# while IFS=, read -r col1 col2 _; do -# echo "$col1, $col2" -# done < "$MAPPING_FILE`" +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