replaceshellcript中的另一个文件中的一个文件的键:值?

我有一个“数据库文件”与键值条目,我有另一个文件的密钥出现在其他内容中。 现在我想用我的键值文件的值replace该关键字。 例:

有一个文件“keys.txt”和“关键字空间url”:

name1 https://maps.google.com something http://www.domain.com/bla.php?value=500 blabla http://thisis.example.com/moooooar.asp 

我有另一个文件“text.txt”每行有一个或几个字,如下所示:

 notrelated somewhatrelated blabla blabla unimportant asdf asdf asdf name1 dadadada 

结果我想要这样的东西:

 notrelated somewhatrelated http://thisis.example.com/moooooar.asp http://thisis.example.com/moooooar.asp unimportant asdf asdf asdf https://maps.google.com dadadada 

其实我的问题是非常相似的https://stackoverflow.com/questions/5283653/,但非提到的解决scheme确实工作,因为我正在与url(斜杠,冒号…)我想?

 awk ' NR==FNR {url[$1]=$2; next} {for (i=1; i<=NF; i++) if ($i in url) $i=url[$i]; print} ' keys.txt text.txt 
 notrelated somewhatrelated http://thisis.example.com/moooooar.asp http://thisis.example.com/moooooar.asp unimportant asdf asdf asdf https://maps.google.com dadadada 

那么,这是有效的(但可能会打破,如果你在你的键逗号):

 while read kv; do sed -e "s,$k,$v,g" -i text.txt; done < keys.txt