You have to worry about the slashes in the text you are replacing.
- Either: use '
\/
' for each slash,
- Or: cheat and use '
.
' to match any character at the point where the slash should appear.
The alternative exploits the improbability of a file containing the HTML. Theoretically, if you don't like the second alternative, you should also use '\.
' at each point where '.
' appears in the string you're looking at.
sed -e 's/<SCRIPT LANGUAGE="JavaScript" TYPE="text.javascript" SRC=".height.js"><.SCRIPT>/ /' file_names
This is copied from your example and slashes are replaced by dots. However, supplying all the file names on the command line like that will simply write the output as the concatenation of all the edited files to standard output.
Classically, to edit files more or less in situ, you'd write:
tmp=${TMPDIR:-/tmp}/xxx.$$
trap 'rm -f $tmp; exit 1' 0 1 2 3 13 15
for file in ...list...
do
sed -e '...' $file > $tmp
mv $tmp $file
done
rm -f $tmp
trap 0
This includes reasonably bullet-proof clean-up of the temporary - it is not perfect. This variant backs up the original before replacing it with the edited version:
tmp=${TMPDIR:-/tmp}/xxx.$$
trap 'rm -f $tmp; exit 1' 0 1 2 3 13 15
for file in ...list...
do
sed -e '...' $file > $tmp
mv $file $file.bak
mv $tmp $file
done
rm -f $tmp
trap 0
With GNU sed
, you can use the '-i
' or '--in-place
' option to overwrite the files; you can use '--in-place=.bak
' to create backup copies of each file
in file.bak
.