I'm trying to replace a string in a file. i have to use a variable since i have to do this in alot of lines. how do i escape the backslash?
text.txt:
1234567#Hello World#Hello I\u0027m Scott
script:
#!/bin/bash
FOLDERID=`cat text.txt | cut -d# -f1` # example: 12345
oldstring=`cat text.txt | cut -d# -f2` # example: "Hello World"
newstring=`cat text.txt | cut -d# -f3` # example: "Hello I\u0027m Scott"
sed -i "s/${oldstring}/${newstring}/g" $FOLDERID/myfile.txt
cat myfile.txt after sed
Hello I0027m Scott
how can i escape a backslash? i only know how to escape slashes which would work like:
newstring=Hello I/u0027m Scott
newstring=${newstring//\//\\\/}
echo ${newstring} # => Hello I\/u0027m Scott