On Thu, Apr 25, 2002 at 10:25:18AM +0200, Alain wrote: > Hello all, > > I've the following problem: > I need to erase about 150 lines (always the same lines) at the end of a serie > of files. > What I have done in the shell is: > #perl -pi -e "s/sub html_base[\s\S]*//" *cgi
2 options: A. perl -p0i -e 's/sub html_base.*//s' *.cgi reads the whole file in one (-0 means $/ = \000), then the '/s' at the end of the regexp treats the whole $_ that now contains the complete file as a *single line*. Problems: -0 only works with text files, since binaries might contain 0-bytes. use -00777 to be absolutely safe, since there's no character 256. Due to the '/s' you can't match on beginning or end of line anymore. B. perl -li -ne '$x = 1 if /^sub_html_base/; print unless $x' *.cgi The '-n' does mostly the same as -p, except it doesn't print. That's up to you, so now you have the option not to print. I usually use the '-l' since I don't need to care for the '\n' when replacing text, but that's not necessary here. Problems: Longer to type and most probably slower. For both versions read 'perldoc perlrun' and look up the details of '-0' and '-n', and eventually '-l'. -- If we fail, we will lose the war. Michael Lamertz | +49 221 445420 / +49 171 6900 310 Nordstr. 49 | [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany | http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]