Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed with & in variable

Tags:

variables

sed

I would like to search and replace with sed and replace with something in a variable which is containing some specials symbols like &.

For example I done something like that:

sed "s|http://.*|http://$URL|"

where URL=1.1.1.1/login.php?user=admin&pass=password. I thinks it became a problem because I use ? and & in my variable.

How can I do my search and replace?

like image 550
pl0nk001 Avatar asked Jan 18 '10 10:01

pl0nk001


1 Answers

URL="1.1.1.1/login.php?user=admin&pass=password"
URL=$(echo "$URL" | sed 's/&/\\&/')    # substitute to escape the ampersand
echo "$OTHER" | sed "s|http://.*|http://$URL|"
like image 96
Dennis Williamson Avatar answered Oct 09 '22 11:10

Dennis Williamson