Re: A little sed
Hans wrote:
>Three questions for the expers:
>
>- I need to clean up a bunch of html files from <SCRIPT> </SCRIPT> tags. I
>tried sed -e s/\<SCRIPT.*SCRIPT\>// file.html > file.html2, but it only
>deletes the first line, not the whole script. The /m modifier doesn't seem
>to work. How do I go about it.
If it only deletes the first line, the other lines don't match the
given pattern. sed operates on each line in turn.
Your pattern will remove <SCRIPTanythingSCRIPT> from any individual
line. It won't work with multilines; since you don't show the data
you're operating on, I can't be precise.
Come to think of it, your problem may be that you aren't quoting the
editing instruction, so the * will be replaced by a list of files
in the current directory; I'm surprised you don't get a whole lot
of errors from that.
Use single quotes around the editing instruction, so you won't need
to escape anything inside it:
sed -e 's/<SCRIPT.*SCRIPT>//'
>- Is it possible to overwrite the original file, not redirect to an
>alterate file?
No.
>- How do I process a bunch of files at once? sed -e s/foo/bar/ *.html >
>*html2 doesn't seem to do it. Or need it be something like for $i in *
>do....? I can't seem to get this to work either.
for f in *.html
do
echo Processing $f
sed -e 's/foo/bar/' $f > $$
mv $$ $f
done
--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47 6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"Wash me thoroughly from mine iniquity, and cleanse me
from my sin. For I acknowledge my transgressions; and
my sin is ever before me. Against thee, thee only,
have I sinned, and done this evil in thy sight..."
Psalms 51:2-4
Reply to: