Variante modificada alienth (as matrizes são usadas):
#!/bin/bash
tr -s ',' ' ' <data.csv | {
read -a tokens
while read -a values; do
for index in $(seq 0 $((${#tokens[*]}-1))); do
echo "s/${tokens[$index]}/${values[$index]}/g"
done | sed -f - sentence.txt
done
}
Mesmo com awk
:
awk -F"[, ]+" '
NR == FNR{
s=s $0 "\n"
next}
FNR == 1{
for(i=1;i<=NF;i++)
val[i]=$i
next}
{
p=s
for(i=1;i<=NF;i++)
gsub(val[i], $i, p)
printf p}
' sentence.txt data.csv