Hello awk experts, I want to substitute the data.txt file according to the template.txt file rules:
template.txt contains the following:
hello hola
one uno
two dos
three tre
four quatro
...
...
goodbye adios
data.txt contains the following:
hello my name is David
one of my friends are John
/two three
hello my number two friend is Mark
...
substituted.txt contains:
hola my name is David
uno of my friends are John
/dos tres
hola my number dos friend is Mark
...
I got this command to work:
awk 'NR==FNR {a[$1]=$2;next} {for ( i in a ) gsub(i,a)}1' templates.txt data.txt > substituted.txt
But I want to skip the string that starts with "/" to NOT substitue (ie. remain as /two) so I added the !/^\//
awk 'NR==FNR {a[$1]=$2;next} {for ( i in a ) !/^\//; gsub(i,a)}1' templates.txt data.txt > substituted.txt
Now, this command doesn't substitue at all now. What am I doing wrong?
Any help is greatly appreciated. Thank you!
template.txt contains the following:
hello hola
one uno
two dos
three tre
four quatro
...
...
goodbye adios
data.txt contains the following:
hello my name is David
one of my friends are John
/two three
hello my number two friend is Mark
...
substituted.txt contains:
hola my name is David
uno of my friends are John
/dos tres
hola my number dos friend is Mark
...
I got this command to work:
awk 'NR==FNR {a[$1]=$2;next} {for ( i in a ) gsub(i,a)}1' templates.txt data.txt > substituted.txt
But I want to skip the string that starts with "/" to NOT substitue (ie. remain as /two) so I added the !/^\//
awk 'NR==FNR {a[$1]=$2;next} {for ( i in a ) !/^\//; gsub(i,a)}1' templates.txt data.txt > substituted.txt
Now, this command doesn't substitue at all now. What am I doing wrong?
Any help is greatly appreciated. Thank you!