Escape characters in shell Escape characters in shell unix unix

Escape characters in shell


The problem is that you're not escaping the special characters in the text, such as the / delimiter.

The easiest solution is to pick a different delimiter and to specify only a part of the string, for instance

find . -name '*.html' -o -name '*.htm' |  xargs fgrep -l '<script>i=0;try' |  xargs perl -i.infected -pe 's#<script>i=0;try.*?</script>##g'

(untested) may do the job.(The .*? construct picks the shortest match; I don't know how to do that in sed.)

Verify with something like

find . -name '*.infected' | sed -e 's#.*#diff & &#' -e 's#.infected##' | sh -x


The sed error came from the fact that the syntax for search and replace is:

s/text/replace/options

But in your text a / appears, so the get the parts test, replace and options wrong.There is an easy solution. sed does not need to use the / as the delimiter between the argumens. You can use any char you want. Just pick one not appearing in your text, e.g # or % (the first delimiter (the one after the intial s) is the delimiter he expects in the rest of the command)..