Replace an expression with special characters by a

2019-09-20 15:17发布

问题:

This question already has an answer here:

  • Is it possible to escape regex metacharacters reliably with sed 2 answers

In a file x, a line containing 4*4 4*1 4*4 4*0 is to be replaced by 4*4 4*1 3*4 1*4 4*0 which is in file y. I'm using the following code:

#!/bin/bash
old=`grep "4*4" x`;
new=`grep "4*4" y`;
sed -i "s/${old}/${new}/g" x

but it yields no change at all in x. I'm a novice and this might be a silly question for this site but I'm unable to replace this expression with multiple special characters with another expression.

回答1:

Welcome to stackOverflow - An awesome platform for developers