I will tell you what my question is about before actually asking - do not hesitate to skip this section!
Some information about my setup
To update files manually in the software system, I create a bash script to remove all files that are not in the new version using diff:
for i in $(diff -r old new 2>/dev/null | grep "Only in old" | cut -d "/" -f 3- | sed "s/: /\//g"); do echo "rm -f $i" >> REMOVEOLDFILES.sh; done
It works great. However, apparently, my files often have a dollar sign ($) in the file name, this is due to some permutations of the GWT structure. Here is one sample line from the bash script created above:
rm -f var/lib/tomcat7/webapps/ROOT/WEB-INF/classes/ExampleFile$3$1$1$1$2$1$1.class
Running this script will not delete the necessary files, because bash reads them as argument variables. Therefore, I need to escape the dollar sign with "\ $".
My actual question
Now I want to add sed-Command to the above pipeline, replacing this dollar sign. In fact, sed also reads the dollar sign as a special character for regular expressions, so obviously I need to avoid it too. But for some reason this does not work, and I could not find an explanation after the multiplayer game.
Here are some options I've tried:
echo "Bla$bla" | sed "s/\$/2/g"
echo "Bla$bla" | sed 's/$$/2/g'
echo "Bla$bla" | sed 's/\\$/2/g'
echo "Bla$bla" | sed 's/@"\$"/2/g'
echo "Bla$bla" | sed 's/\\\$/2/g'
The desired result in this example should be "Bla2bla". What am I missing? I am using GNU sed 4.2.2
EDIT
I just realized that the above example is wrong for a start - the echo command already interprets the $ variable as a variable, and the following sed does not get it anyway ... Here is the correct example:
- Create a text file
testwith the contentsbla$bla cat test gives bla$blacat test | sed "s/$/2/g" gives bla$bla2cat test | sed "s/\$/2/g" gives bla$bla2cat test | sed "s/\\$/2/g" gives bla2bla
, - . : , , .