Re: A little sed
N. Raghavendra wrote: On Fri, Jan 26, 2001 at 11:19:53AM +0100, Hans wrote: - 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. - Is it possible to overwrite the original file, not redirect to an alterate file? - 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. Hi, You could use the shell scripts 'overwrite' and 'replace' in Kernighan and Pike, The UNIX programming environment, Chapter 5, Section 5.5, pages 154-155. Best, Raghavendra. Hi, perheps you can solve the problem with awk, where you can set variables in the script. Greetings Albrecht
A little sed
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. - Is it possible to overwrite the original file, not redirect to an alterate file? - 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. TIA, Hans
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[EMAIL PROTECTED] 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
Re: A little sed
On Fri, Jan 26, 2001 at 11:19:53AM +0100, Hans wrote: - 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. - Is it possible to overwrite the original file, not redirect to an alterate file? - 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. Hi, You could use the shell scripts 'overwrite' and 'replace' in Kernighan and Pike, The UNIX programming environment, Chapter 5, Section 5.5, pages 154-155. Best, Raghavendra. -- N. Raghavendra [EMAIL PROTECTED] | Another year is gone - Harish-Chandra Research Institute | A travel hat on my head, GnuPG public key at:| Straw sandals on my feet. http://riemann.mri.ernet.in/~raghu/ | -- Matsuo Basho
Re: A little sed
On Fri, Jan 26, 2001 at 11:19:53AM +0100, Hans wrote: - 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. Can't say much on this without seeing the data you're trying to mung. - Is it possible to overwrite the original file, not redirect to an alterate file? - 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. I can help you with these two, though. Below, you'll find doall.pl, a perl script I hacked up for a similar situation (sedding a bunch of C source files, in my case). Usage is simply doall.pl sed -e 'your regex here' *.html --- begin script --- #!/usr/bin/perl -w use strict; my $cmd = shift; while (my $filename = shift) { # Perform operation to new file. Exit on error. # TODO: On error, report command that caused problem and the resulting #error message before dying. if (`$cmd $filename 21 $filename.new`) { die }; # If the output is different than the input, replace the old version with # the new one. If nothing was changed, discared the new version and leave # the old one untouched. if (`diff $filename.new $filename`) { rename $filename.new, $filename; } else { unlink $filename.new; } } --- end script --- -- SGI products are used to create the 'Bugs' that entertain us in theatres and at home. - SGI job posting Geek Code 3.1: GCS d? s+: a- C++ UL++$ P+ L+++ E- W--(++) N+ o+ !K w---$ O M- V? PS+ PE Y+ PGP t 5++ X+ R++ tv b+ DI D G e* h+ r y+