Here is an example how to replace text containing slashes with new text that also contains slashes. It will ultimately convert "A cool website is http://www.yahoo.com" to "A cool website is http://www.google.com" #!/bin/bash A="http://www.google.com"; B="http://www.yahoo.com"; C="A cool website is $B"; echo "A = $A"; echo "B = $B"; echo "C = $C"; A=`echo "$A" | sed 's/\//\\\\\//g'` B=`echo "$B" | sed 's/\//\\\\\//g'` echo "----------After Running Fixing----------"; echo "A = $A"; echo "B = $B"; echo "C = $C"; echo "-----------After running sed------------"; echo "$C" | sed "s/$B/$A/g"