Re: help about perl -pi -e

2002-04-25 Thread Alain

On Thursday 25 April 2002 15:41, you wrote:
| Hi,
|
| Am Donnerstag, 25. April 2002 15:20 hast Du geschrieben:
| > exact, that's it.
| > but i've got the solution to that problem (i forgot to put the trailing
| > 's' in my post, but i used it and it did not work)
| > the solution is:
| > perl -p0i -e 's/sub html_base.*//s' *.cgi
|
| and it happily removes from everything that starts with html_base to the
| end of the file. This is wrong.
|
| sub html_baseball {
|
| better you write
| perl -p0i -e 's/sub html_base\s*{.*//s' *.cgi
|
| > it does exactly what i need, and is very fast.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: help about perl -pi -e

2002-04-25 Thread Alain

On Thursday 25 April 2002 15:52, Bob Showalter wrote:
| > -Original Message-
| > From: Bob Showalter [mailto:[EMAIL PROTECTED]]
| > Sent: Thursday, April 25, 2002 9:46 AM
| > To: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
| > Subject: RE: help about perl -pi -e
| >
| > ...
| >
| > Do you want to delete all the lines in each file
| > that follow "sub html_base[sS]"? If so, try this:
| >
| >perl -n -i.bak -e 'print unless /sub html_base[sS]/ .. eof'
|
| Oops, I forgot to put some files on there. Should be:
|
|perl -n -i.bak -e 'print unless /sub html_base[sS]/ .. eof' *.cgi
|
| or similar.

thanks a lot for helping.
someone gave me the solution:
perl -p0i -e 's/sub html_base.*//s' *.cgi
it did exactly what i wanted:
remove all the lines below "sub html_base"

thanks again

Alain Scieur



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: help about perl -pi -e

2002-04-25 Thread Bob Showalter

> -Original Message-
> From: Bob Showalter [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, April 25, 2002 9:46 AM
> To: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
> Subject: RE: help about perl -pi -e
> 
> ...
>
> Do you want to delete all the lines in each file
> that follow "sub html_base[sS]"? If so, try this:
> 
>perl -n -i.bak -e 'print unless /sub html_base[sS]/ .. eof'

Oops, I forgot to put some files on there. Should be:

   perl -n -i.bak -e 'print unless /sub html_base[sS]/ .. eof' *.cgi

or similar.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: help about perl -pi -e

2002-04-25 Thread Bob Showalter

> -Original Message-
> From: Alain [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, April 25, 2002 4:25 AM
> To: [EMAIL PROTECTED]
> Subject: help about perl -pi -e
> 
> 
> 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
> 
> But this command only erase one line at once.
> And I want to erase all the lines in one time.
> Is there anybody who can help?

What do you mean by "erase all the lines?"

The command you have written will change all of
the matching lines in each file.

Do you want to delete all the lines in each file
that follow "sub html_base[sS]"? If so, try this:

   perl -n -i.bak -e 'print unless /sub html_base[sS]/ .. eof'

That prints each line unless it lies between the
line containing sub html_base[sS] and the end of
the current file.

   perldoc perlop (search for "Range Operators")
   perldoc -f eof

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: help about perl -pi -e

2002-04-25 Thread Matthew Weier O'Phinney

I'm not quite sure what you're trying to do with this... but from what
you've provided, the regular expression you wrote will only remove text
matching "sub html_base" on a single line -- and not even the
newline at the end. The '-pi' switches will grab a single line at a time
from the currently open file to compare to the expression. 

It sounds like you've got a subroutine you're trying to remove from some
files:
 sub html_base {
 ...
 }
yes? If so, it might make more sense to make a quick-and-dirty perl
script that will take the fileglob (*cgi), read one file at a time, and
read that entire file into a single string, and then run the regexp you 
wrote against it, with the following addition:
 s/sub html_base[\s\S]*//s
The trailing 's' will allow the regexp to look over newlines (\n) when
matching.

--Matthew

On Thu, 25 Apr 2002 04:10:58 -0400, 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
> 
> But this command only erase one line at once. And I want to erase all
> the lines in one time. Is there anybody who can help?
> 
> Thanks a lot
> 
> Alain Scieur

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: help about perl -pi -e

2002-04-25 Thread Michael Lamertz

On Thu, Apr 25, 2002 at 05:02:10AM -0700, John W. Krahn wrote:
> Michael Lamertz wrote:
> > 
> > A.
> > perl -p0i -e 's/sub html_base.*//s' *.cgi
> > 
> > reads the whole file in one
> 
> > (-0 means $/ = \000),
> 
> \000 is a reference to a numeric literal, "\000" is the null character
> which doesn't "reads the whole file in one"

Yepp, that wasn't intended to be a proper perl expression but more kind
of symbolic.  I used the C notation where \nnn puts raw characters into
strings %-)

Sorry, that was unclear.

> >   -0 only works with text files, since binaries might contain 0-bytes.
> > use -00777 to be absolutely safe, since there's no character 256.
> 
> Octal 0777 is not equal to 256.
> 
> $ perl -le'print 0777'
> 511

Again you're right.  That'll teach me to not only type but also think
when I post next time @-)

> >   Due to the '/s' you can't match on beginning or end of line anymore.
> 
> If you use the /m modifier then ^ will match the beginning of a line and
> $ will match the end of a line.

Yepp, but this isn't what he needed.  He wanted to match up to EOF.  I
only mentioned it so he was aware of the, hmmm, "side effect".

-- 
   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]




Re: help about perl -pi -e

2002-04-25 Thread John W. Krahn

Michael Lamertz wrote:
> 
> A.
> perl -p0i -e 's/sub html_base.*//s' *.cgi
> 
> reads the whole file in one

perldoc perlrun
[snip]
 -0[digits]
  specifies the input record separator (`$/') as an
  octal number.  If there are no digits, the null charĀ­
  acter is the separator.  Other switches may precede
  or follow the digits.  For example, if you have a
  version of find which can print filenames terminated
  by the null character, you can say this:

  find . -name '*.orig' -print0 | perl -n0e unlink

  The special value 00 will cause Perl to slurp files
  in paragraph mode.  The value 0777 will cause Perl to
  slurp files whole because there is no legal character
  with that value.


> (-0 means $/ = \000),

\000 is a reference to a numeric literal, "\000" is the null character
which doesn't "reads the whole file in one"


> 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.

Octal 0777 is not equal to 256.

$ perl -le'print 0777'
511


>   Due to the '/s' you can't match on beginning or end of line anymore.

If you use the /m modifier then ^ will match the beginning of a line and
$ will match the end of a line.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: help about perl -pi -e

2002-04-25 Thread Michael Lamertz

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]




help about perl -pi -e

2002-04-25 Thread Alain

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

But this command only erase one line at once.
And I want to erase all the lines in one time.
Is there anybody who can help?

Thanks a lot

Alain Scieur

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]