How to replace a string in a file using another file as source?

I have a file with two columns of alpha numeric strings, I need to replace in another file all the appearances of any string in column A with the correspondent string in column B, I tried this but it is not working:

for i in `awk '{print $1}' test_file`; do for j in `awk '{print $2}' test_file`; do sed 's/$i/$j/g' test_file1  > test_file2; done; done

as a test if I do this:

for i in `awk '{print $1}' test_file`; do for j in `awk '{print $2}' test_file`; do echo $i:$j; done; done

I got the list of strings correctly, but the replacement doesn't work

awk 'FNR==NR{ a[$1] = $2; next} { for(i in a)gsub(i, a) }1'  string_list_file file > outfile

Here is example to start

akshay@db-3325:/tmp$ cat string_list_file 
foo bar
jack john
me you

akshay@db-3325:/tmp$ cat file 
1 2 3 jack 5
me 2 3 foo 5
me jack foo 4 5

akshay@db-3325:/tmp$ awk 'FNR==NR{ a[$1] = $2; next} { for(i in a)gsub(i, a) }1'  string_list_file file 
1 2 3 john 5
you 2 3 bar 5
you john bar 4 5
1 Like

:slight_smile: it worked...thanks!