Save this to a file e.g. script.sh.
#!/bin/bash
declare -A A
while read -ra __; do
A[${__[0]}]=${__[1]}
done < "$2"
while read -r __; do
for I in "${!A[@]}"; do
[[ $__ == *"$I"* ]] && {
V=${A[$I}
__=${__//"$I"/"$V"}
}
done
echo "$__"
done < "$1"
Then run bash script.sh aaa.txt bbb.txt.
To get the output run it as something like bash script.sh aaa.txt bbb.txt > out.txt
I prefer to use Bash this time since you have to quote non-literals in Awk.
Another solution through Ruby:
ruby -e 'f = File.open(ARGV[0]).read; File.open(ARGV[1]).readlines.map{|l| l.split}.each{|a| f.gsub!(a[0], a[1])}; puts f' aaa.txt bbb.txt
Another way to modify file directly:
#!/bin/bash
A=$(<"$1")
while read -ra B; do
A=${A//"${B[0]}"/"${B[1]}"}
done < "$2"
echo "$A" > "$1"
Run as bash script.sh aaa.txt bbb.txt.
Another through Ruby:
ruby -e 'x = File.read(ARGV[0]); File.open(ARGV[1]).readlines.map{|l| l.split}.each{|a| x.gsub!(a[0], a[1])}; File.write(ARGV[0], x)' aaa.txt bbb.txt