Ask a Question related to PERL Beginners, Design and Development.
-
George Georgalis #1
recursive replace command line
Hi -
giving my perl a retry, I found some hints on a website to recursively
replace text
perl -p -i -e 's/old\(.\)atext/new\1btext/g;' $( find ./ -name '*.html' -o -name '*.txt' )
this should replace "old-atext" with "new-btext" and "old+atext" with
"new+btext" and similar occurrences in all the files from find.
but from what I can tell, perl doesn't support the \1 for \(*\) symbols
like sed does. What is the work around?
// George
--
GEORGE GEORGALIS, System Admin/Architect cell: 646-331-2027 <IXOYE><
Security Services, Web, Mail, mailto:george@galis.org
Multimedia, DB, DNS and Metrics. [url]http://www.galis.org/george[/url]
George Georgalis Guest
-
#40715 [NEW]: level too deep - recursive dependency? in Unknown on line 0
From: shoichi at cf7 dot so-net dot ne dot jp Operating system: CentOS4.4 PHP version: 5.2.1 PHP Bug Type: Scripting Engine... -
command line search and replace
Hi all, When I try the following, perl reads the * as a literal character, instead of my intent as a global value. Anyone see what I am missing? ... -
RUN/execute a Command-Line command from an ASP page
Hi, I need to RUN/execute a Command-Line command from an ASP page. This is the command: sse45.exe -i k:\o\2.wmv -o k:\o\2.shh -w 128 -df 0 -m 2... -
RUN/execute a Command-Line command from an ASP page.
Hi, I need to RUN/execute a Command-Line command from an ASP page. This is the command: sse45.exe -i k:\o\2.wmv -o k:\o\2.shh -w 128 -df 0 -m 2... -
Replace-Color Command won't work
duplicate post -
Jeff 'Japhy' Pinyan #2
Re: recursive replace command line
On Dec 10, George Georgalis said:
This isn't recursively replacing text; it's recursively going through a>giving my perl a retry, I found some hints on a website to recursively
>replace text
>
>perl -p -i -e 's/old\(.\)atext/new\1btext/g;' $( find ./ -name '*.html' -o -name '*.txt' )
directory tree.
Because Perl is not sed. Perl uses (...), not \(...\) for its memory>but from what I can tell, perl doesn't support the \1 for \(*\) symbols
>like sed does. What is the work around?
capturing. In Perl's regexes, all non-alphanumeric metacharacters don't
use backslashes. That means [...] for character classes, not \[...\], and
+ for " 1 or more", not \+, and so on.
--
Jeff "japhy" Pinyan [email]japhy@pobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
Jeff 'Japhy' Pinyan Guest
-
George Georgalis #3
Re: recursive replace command line
On Thu, Dec 11, 2003 at 09:05:20AM -0500, Jeff 'japhy' Pinyan wrote:
that's what I needed to hear... however replacing text (with memory>On Dec 10, George Georgalis said:
>>>>giving my perl a retry, I found some hints on a website to recursively
>>replace text
>>
>>perl -p -i -e 's/old\(.\)atext/new\1btext/g;' $( find ./ -name '*.html' -o -name '*.txt' )
>This isn't recursively replacing text; it's recursively going through a
>directory tree.
>>>>but from what I can tell, perl doesn't support the \1 for \(*\) symbols
>>like sed does. What is the work around?
>Because Perl is not sed. Perl uses (...), not \(...\) for its memory
>capturing. In Perl's regexes, all non-alphanumeric metacharacters don't
>use backslashes. That means [...] for character classes, not \[...\], and
>+ for " 1 or more", not \+, and so on.
capturing) is still a problem:
perl -p -i -e 's/451(.)8229/331\12027/g;' $( find ./ -type f -name '*.html' -o -name '*.txt' )
here I'm trying to replace instances of of a phone number, that might
use "-" " " or "." to separate the first and second parts.
451-8229 to 331-2027
451 8229 to 331 2027
etc
the result "331P27" hinted 3 digits may be used for the call back
perl -p -i -e 's/451(.)8229/331\0012027/g;' $( find ./ -type f -name '*.html' -o -name '*.txt' )
that puts the characters where they go but the dash has changed to some
other character (an ascII 001 I suppose).
// George
--
GEORGE GEORGALIS, System Admin/Architect cell: 646-331-2027 <IXOYE><
Security Services, Web, Mail, mailto:george@galis.org
Multimedia, DB, DNS and Metrics. [url]http://www.galis.org/george[/url]
George Georgalis Guest
-
Jeff 'Japhy' Pinyan #4
Re: recursive replace command line
On Dec 11, George Georgalis said:
Right; first of all, \1 should only be used IN the regex ITSELF. Outside>On Thu, Dec 11, 2003 at 09:05:20AM -0500, Jeff 'japhy' Pinyan wrote:>>>On Dec 10, George Georgalis said:
>>>>>>>giving my perl a retry, I found some hints on a website to recursively
>>>replace text
>>>
>>>perl -p -i -e 's/old\(.\)atext/new\1btext/g;' $( find ./ -name '*.html' -o -name '*.txt' )
>>This isn't recursively replacing text; it's recursively going through a
>>directory tree.
>>>>>>>but from what I can tell, perl doesn't support the \1 for \(*\) symbols
>>>like sed does. What is the work around?
>>Because Perl is not sed. Perl uses (...), not \(...\) for its memory
>>capturing. In Perl's regexes, all non-alphanumeric metacharacters don't
>>use backslashes. That means [...] for character classes, not \[...\], and
>>+ for " 1 or more", not \+, and so on.
>that's what I needed to hear... however replacing text (with memory
>capturing) is still a problem:
>
>perl -p -i -e 's/451(.)8229/331\12027/g;' $( find ./ -type f -name '*.html' -o -name '*.txt' )
of the regex, you should use $1. However, "331$12027" still isn't
appropriate; you'll need "331${1}2027". The reason "331\12027" gave you
"331P27" is because octal character 120 is "P".
--
Jeff "japhy" Pinyan [email]japhy@pobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
Jeff 'Japhy' Pinyan Guest
-
George Georgalis #5
Re: recursive replace command line
On Thu, Dec 11, 2003 at 11:21:39AM -0500, Jeff 'japhy' Pinyan wrote:
Thanks,>On Dec 11, George Georgalis said:
>>>>On Thu, Dec 11, 2003 at 09:05:20AM -0500, Jeff 'japhy' Pinyan wrote:>>>>>On Dec 10, George Georgalis said:
>>>
>>>>giving my perl a retry, I found some hints on a website to recursively
>>>>replace text
>>>>
>>>>perl -p -i -e 's/old\(.\)atext/new\1btext/g;' $( find ./ -name '*.html' -o -name '*.txt' )
>>>
>>>This isn't recursively replacing text; it's recursively going through a
>>>directory tree.
>>>
>>>>but from what I can tell, perl doesn't support the \1 for \(*\) symbols
>>>>like sed does. What is the work around?
>>>
>>>Because Perl is not sed. Perl uses (...), not \(...\) for its memory
>>>capturing. In Perl's regexes, all non-alphanumeric metacharacters don't
>>>use backslashes. That means [...] for character classes, not \[...\], and
>>>+ for " 1 or more", not \+, and so on.
>>that's what I needed to hear... however replacing text (with memory
>>capturing) is still a problem:
>>
>>perl -p -i -e 's/451(.)8229/331\12027/g;' $( find ./ -type f -name '*.html' -o -name '*.txt' )
>Right; first of all, \1 should only be used IN the regex ITSELF. Outside
>of the regex, you should use $1. However, "331$12027" still isn't
>appropriate; you'll need "331${1}2027". The reason "331\12027" gave you
>"331P27" is because octal character 120 is "P".
perl -p -i -e 's/347(.)451(.)8229/646${1}331${2}2027/g;' $( find ./ -type f -name '*.html' -o -name '*.txt' )
perl -p -i -e 's/347(..)451(.)8229/646${1}331${2}2027/g;' $( find ./ -type f -name '*.html' -o -name '*.txt' )
worked perfect to update my web pages... :)
btw - what's the best manpage for the perl command line options?
TAI,
// George
--
GEORGE GEORGALIS, System Admin/Architect cell: 646-331-2027 <IXOYE><
Security Services, Web, Mail, mailto:george@galis.org
Multimedia, DB, DNS and Metrics. [url]http://www.galis.org/george[/url]
George Georgalis Guest
-
R. Joseph Newton #6
Re: recursive replace command line
George Georgalis wrote:
Hi George,>
> that's what I needed to hear... however replacing text (with memory
> capturing) is still a problem:
>
> perl -p -i -e 's/451(.)8229/331\12027/g;' $( find ./ -type f -name '*.html' -o -name '*.txt' )
If you are going to do your regex work--especially at a high level--in Perl, it is imperative that
you read the Perl documentation. The problem in the above sam[ple, or the one that jumps out at me,
is that you are using the backslash form of back reference in the replacement string. In the Perl
implementation, that is not appropriate. Use the built-in scalars ($1, $2 ...) instead. Backslash
backreferences are used within the scanning portion of the regex, but not in the replqacement
string.
Please read:
perldoc perlre
Joseph
R. Joseph Newton Guest
-
George Georgalis #7
Re: recursive replace command line
On Thu, Dec 11, 2003 at 11:07:53AM -0800, R. Joseph Newton wrote:
Thanks for the pointer, Joseph. Indeed, I'm not yet up to speed on>If you are going to do your regex work--especially at a high level--in Perl, it is imperative that
>you read the Perl documentation. The problem in the above sam[ple, or the one that jumps out at me,
>is that you are using the backslash form of back reference in the replacement string. In the Perl
>implementation, that is not appropriate. Use the built-in scalars ($1, $2 ...) instead. Backslash
>backreferences are used within the scanning portion of the regex, but not in the replqacement
>string.
>
>Please read:
>perldoc perlre
accessing perl-doc, there is quite a lot. ;-)
Bye,
// George
--
GEORGE GEORGALIS, System Admin/Architect cell: 646-331-2027 <IXOYE><
Security Services, Web, Mail, mailto:george@galis.org
Multimedia, DB, DNS and Metrics. [url]http://www.galis.org/george[/url]
George Georgalis Guest
-
Paul Johnson #8
Re: recursive replace command line
On Thu, Dec 11, 2003 at 12:17:03PM -0500, George Georgalis wrote:
perlrun> btw - what's the best manpage for the perl command line options?
--
Paul Johnson - [email]paul@pjcj.net[/email]
[url]http://www.pjcj.net[/url]
Paul Johnson Guest



Reply With Quote

