Re: search replace saved to a variable

2009-09-03 Thread Jenda Krynicky
From: Noah Garrett Wallach > okay a step further - is there a way to make the following a one liner? > > (my $filename_cmd = $cmd[-1]) =~ s/\|//g; > $filename_cmd =~ s/\s+/\./g; > $filename_cmd =~ s/save.*//g; There's no point in making it a one liner. Plus anything may be writen

Re: search replace saved to a variable

2009-09-02 Thread Uri Guttman
> "NGW" == Noah Garrett Wallach writes: NGW> Jim Gibson wrote: >> At 7:22 PM -0700 9/2/09, Noah Garrett Wallach wrote: >>> Hi there, >>> >>> what is the way to collapse this search/replace to one line? >>> >>> my $filename_cmd = $cmd[-1]; >>> my $filename_cmd =~ s/\s/\./;

Re: search replace saved to a variable

2009-09-02 Thread Noah Garrett Wallach
Jim Gibson wrote: At 7:22 PM -0700 9/2/09, Noah Garrett Wallach wrote: Hi there, what is the way to collapse this search/replace to one line? my $filename_cmd = $cmd[-1]; my $filename_cmd =~ s/\s/\./; (my $filename_cmd = $cmd[-1]) =~ s/\s/\./; thanks, okay a step further -

Re: search replace saved to a variable

2009-09-02 Thread Jim Gibson
At 7:22 PM -0700 9/2/09, Noah Garrett Wallach wrote: Hi there, what is the way to collapse this search/replace to one line? my $filename_cmd = $cmd[-1]; my $filename_cmd =~ s/\s/\./; (my $filename_cmd = $cmd[-1]) =~ s/\s/\./; -- Jim Gibson jimsgib...@gmail.com -- To unsubscribe

Re: search replace one liner problem

2007-10-09 Thread jrpfinch
Thanks very much - this works Jon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: search replace one liner problem

2007-09-17 Thread John W. Krahn
jrpfinch wrote: I would like to execute the following regex on a file: s/(\$Revision:\s+)(\d+\.\d+)(\s+\$.+use constant VERSION\s+=> ")(.+?) (")/$1$2$3Revision $2$5/gs I am doing this in bash as follows: REGEX='s/(\$Revision:\s+)(\d+\.\d+)(\s+\$.+use constant VERSION\s+=> ") (.+?)(")/$1$2$3Rev

Re: SEARCH & REPLACE

2004-05-05 Thread James Edward Gray II
On May 5, 2004, at 2:11 PM, Madhu Reddy wrote: Then code which i sent is inside subroutine.. Then at least drop all those crazy symbols: unless (open FH_SRC_SCRIPT $src_script) { print "Whatever"; return 0; } Isn't that easier on the eyes? James -- To unsubscribe, e-mail: [EMAIL PRO

Re: SEARCH & REPLACE

2004-05-05 Thread James Edward Gray II
On May 5, 2004, at 12:44 PM, Madhu Reddy wrote: James, Thanks for correction.. for u r question regarding file open, following is correct code if (!(open(FH_SRC_SCRIPT, $src_script))) { print "(TERADATA.pl) generate_script:: File $src_script open failed --> $!\n";

Re: SEARCH & REPLACE

2004-05-05 Thread Madhu Reddy
James, Thanks for correction.. for u r question regarding file open, following is correct code if (!(open(FH_SRC_SCRIPT, $src_script))) { print "(TERADATA.pl) generate_script:: File $src_script open failed --> $!\n"; return 0; } if (!(ope

Re: SEARCH & REPLACE

2004-05-05 Thread James Edward Gray II
On May 5, 2004, at 12:26 PM, Madhu Reddy wrote: following is my main script, to simulate that i assigned to $_. Thanks for your solution if (!(open(FH_SRC_SCRIPT, "$src_script"))) { close(FH_SRC_SCRIPT); return 0; } Yuck. What does that say? If we ca

Re: SEARCH & REPLACE

2004-05-05 Thread Madhu Reddy
--- James Edward Gray II <[EMAIL PROTECTED]> wrote: > On May 5, 2004, at 11:03 AM, Madhu Reddy wrote: > > > -replace.pl--- > > #!/bin/perl -w > > > > # INPUT STRING > > my $in_str = ".import "; > > > > # REPLACE STRING > > my $repl = "/home/madhu/apps/toll.txt"; > > > > $_=$in

Re: SEARCH & REPLACE

2004-05-05 Thread James Edward Gray II
On May 5, 2004, at 11:03 AM, Madhu Reddy wrote: -replace.pl--- #!/bin/perl -w # INPUT STRING my $in_str = ".import "; # REPLACE STRING my $repl = "/home/madhu/apps/toll.txt"; $_=$in_str; Why do this? # I don't want to use following, because # "TOLL_FREE" will be changed each tim

Re: Search Replace in multiple files

2004-02-11 Thread Rob Dixon
Chetak Sasalu wrote: > > I came back to office after an extended weekend and realized that my words > might have irked some of you. 'Irked' is a good word. I'll happily forgive just because of that, plus the fact that I know that I also can be irksome. Rob -- To unsubscribe, e-mail: [EMAIL PR

RE: Search Replace in multiple files

2004-02-10 Thread chetak.sasalu
Hello, I came back to office after an extended weekend and realized that my words might have irked some of you. But let me explain. I agree, acquiring the 'mental tools' to do it myself is always the best way. I had tried out a few sample scripts myself (most of them failed). After spend

Re: Search Replace in multiple files

2004-02-07 Thread Jan Eden
Rob Dixon wrote: >Jan Eden wrote: >> >>Rob Dixon wrote: >> >>>John W. Krahn wrote: >> use File::Find; local ( $^I, @ARGV ) = ''; find( { no_chdir => 1, wanted => sub { -f and push @ARGV, $_ } }, './mydir' ); s/foo/bar/g, print while <>; >>> >>>Thanks John. >>> >>>I missed the 'has sub

Re: Search Replace in multiple files

2004-02-07 Thread Rob Dixon
Jan Eden wrote: > > Rob Dixon wrote: > > >John W. Krahn wrote: > > >> use File::Find; > >> local ( $^I, @ARGV ) = ''; > >> find( { no_chdir => 1, wanted => sub { -f and push @ARGV, $_ } }, './mydir' ); > >> s/foo/bar/g, print while <>; > > > >Thanks John. > > > >I missed the 'has subdirectories'

Re: Search Replace in multiple files

2004-02-07 Thread Rob Dixon
John W. Krahn wrote: > > Chetak Sasalu wrote: > > > > Hi, > > Hello, > > > I have to search and replace 'foo' to 'bar' in all the files in a > > directory(has subdirectories). > > The files are about 40k in size. > > > > On the command line I would do it as, > > find ./mydir/ -type f -print | xargs

Re: Search Replace in multiple files

2004-02-06 Thread R. Joseph Newton
Ned Cunningham wrote: > Wouldn't it be better to not waste your time with this kind of response??? > > Ned Cunningham > POS Systems Development Hi Ned, I'd say that it depends on whether you see the OP as a potential programmer. If so, then no, it would not be better. If the OP takes a hint an

Re: Search Replace in multiple files

2004-02-06 Thread John W. Krahn
Chetak Sasalu wrote: > > Hi, Hello, > I have to search and replace 'foo' to 'bar' in all the files in a > directory(has subdirectories). > The files are about 40k in size. > > On the command line I would do it as, > find ./mydir/ -type f -print | xargs perl -pi -e 's/foo/bar/' > > No backup o

RE: Search Replace in multiple files

2004-02-06 Thread Ned Cunningham
les K. Clarkson [mailto:[EMAIL PROTECTED] Sent: Friday, February 06, 2004 9:54 AM To: [EMAIL PROTECTED] Subject: RE: Search Replace in multiple files [EMAIL PROTECTED] <[EMAIL PROTECTED

RE: Search Replace in multiple files

2004-02-06 Thread Charles K. Clarkson
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: : : I went through perldoc perlrun and saw the code. : : I thought it as a criminal waste of time to try and : modify that code for my purpose, when I can ask you : folks :-) Perhaps I am misunderstanding you, but that sounds to me like you would

Re: Search Replace in multiple files

2004-02-06 Thread Randy W. Sims
On 02/06/04 07:45, [EMAIL PROTECTED] wrote: PS: I see this term 'foo' 'bar' in many programming books, what is the etymology of this? It is derived from a technical acronym FUBAR - [EMAIL PROTECTED] Up Beyond All Repair (or Recognition). 'foo', 'bar' is just a play on the original acronym - A jo

Re: Search Replace in multiple files

2004-02-06 Thread Rob Dixon
Chetak Sasalu wrote: > > I have to search and replace 'foo' to 'bar' in all the files in a > directory(has subdirectories). > The files are about 40k in size. > > On the command line I would do it as, > find ./mydir/ -type f -print | xargs perl -pi -e 's/foo/bar/' > > No backup of the original fil

Re: Search Replace in multiple files

2004-02-06 Thread Jan Eden
Please disregard my post, I mixed up the magic <> and the less magic . -- These are my principles and if you don't like them... well, I have others. - Groucho Marx -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: Search Replace in multiple files

2004-02-06 Thread Jan Eden
[EMAIL PROTECTED] wrote: >Hi, > >I have to search and replace 'foo' to 'bar' in all the files in a >directory(has subdirectories). The files are about 40k in size. > >What is the most efficient way to implement this inside a perl >program ? There are about 30 files to be processed. I went through

RE: Search replace using 2 lines for pattern

2004-01-18 Thread Charles K. Clarkson
: -Original Message- : From: Bertrand Mansion [mailto:[EMAIL PROTECTED] : Sent: Sunday, January 18, 2004 7:56 AM : To: Charles K. Clarkson; [EMAIL PROTECTED] : Subject: Re: Search replace using 2 lines for pattern : : : <[EMAIL PROTECTED]> wrote : : : > Bertrand Mansio

Re: Search replace using 2 lines for pattern

2004-01-18 Thread Bertrand Mansion
<[EMAIL PROTECTED]> wrote : > Bertrand Mansion <[EMAIL PROTECTED]> wrote: > : > [snip] > : I have tried many times with no success. I can easily change > : the "Received:" header to be > : "From [EMAIL PROTECTED]:" but as there > : are more than one "Received:" header, they all get replaced, > :

RE: Search replace using 2 lines for pattern

2004-01-18 Thread Charles K. Clarkson
Bertrand Mansion <[EMAIL PROTECTED]> wrote: : [snip] : I have tried many times with no success. I can easily change : the "Received:" header to be : "From [EMAIL PROTECTED]:" but as there : are more than one "Received:" header, they all get replaced, : which is bad. : : I think I need a regex tha

Re: search replace

2003-09-06 Thread Damon Davison
On Saturday 06 September 2003 17:53, Pandey Rajeev-A19514 wrote : : How do I search replace text in a file from a perl script. : i.e. by opening the file in write mode and then do a search : replace. You can do what you want via the regular expression substitution operator "s///" in a "while" lo

Re: search replace

2003-09-06 Thread Steve
perldoc perlre perldoc -f open On Sat, 2003-09-06 at 11:53, Pandey Rajeev-A19514 wrote: > Hi , > > How do I search replace text in a file from a perl script. i.e. by opening the file > in write mode and then do a search replace. > > I don't want to do a command line search replace. > > Regards

Re: search replace

2003-09-06 Thread perlwannabe
> Hi , > > How do I search replace text in a file from a perl script. i.e. by > opening the file in write mode and then do a search replace. > > I don't want to do a command line search replace. Use the s/// operator...as follows: $_ =~ s/oldtext/newtext/gi; this will replace all occurrences of

Re: Search Replace

2003-02-04 Thread Janek Schleicher
On Mon, 03 Feb 2003 10:29:14 -0500, Paul Kraus wrote: > I have an array that I want to remove every instance of '$' and all > leading and trailing white space. > My code only seems to remove '$'. I know I can split this into separate > commands but is there a way to do this all at once? Erm, I do

Re: Search Replace

2003-02-03 Thread Rob Dixon
"Paul Kraus" <[EMAIL PROTECTED]> wrote in message 007001c2cba0$2a952ae0$8afea8c0@pkraus">news:007001c2cba0$2a952ae0$8afea8c0@pkraus... > Nope I wish. > > 3 fields. 1 is a part number, 2 is cost, 3 is list. > I am removing the '$' for 2 and 3. where as I am removing white space > from 1,2,&3. > I w

RE: Search Replace

2003-02-03 Thread Paul Kraus
sage- From: Rob Dixon [mailto:[EMAIL PROTECTED]] Sent: Monday, February 03, 2003 10:54 AM To: [EMAIL PROTECTED] Subject: Re: Search Replace "Paul Kraus" <[EMAIL PROTECTED]> wrote in message 005b01c2cb99$02315ee0$8afea8c0@pkraus">news:005b01c2cb99$02315ee0$8afea8c0@p

Re: Search Replace

2003-02-03 Thread Rob Dixon
"Paul Kraus" <[EMAIL PROTECTED]> wrote in message 005b01c2cb99$02315ee0$8afea8c0@pkraus">news:005b01c2cb99$02315ee0$8afea8c0@pkraus... > I have an array that I want to remove every instance of '$' and all > leading and trailing white space. > My code only seems to remove '$'. I know I can split th

Re: Search Replace

2003-02-03 Thread Frank Wiles
.--[ Paul Kraus wrote (2003/02/03 at 10:29:14) ]-- | | I have an array that I want to remove every instance of '$' and all | leading and trailing white space. | My code only seems to remove '$'. I know I can split this into separate | commands but is there a way to do this all at

Re: Search & Replace Issue

2002-04-09 Thread John W. Krahn
"Kristin A. I." wrote: > > I am trying to indent a scroll-thru menu which has been made > into a tree using the following database query: > select dept_id, LPAD(' ',2*(Level-1))||dept_name dept_name > from depts > start with dept_id = 1 > connect by dept_parent = PRIOR dept_id; > My probl

Re: Search & Replace Issue

2002-04-09 Thread bob ackerman
On Tuesday, April 9, 2002, at 09:39 AM, Kristin A. I. wrote: > I am trying to indent a scroll-thru menu which has been made into a tree > using the following database query: > select dept_id, LPAD(' ',2*(Level-1))||dept_name dept_name > from depts > start with dept_id = 1 > connect by

RE: Search & Replace Issue

2002-04-09 Thread Hanson, Robert
I'm sure that this can be done is less steps, but it works... #!/usr/bin/perl -w use strict; my $line = " stuff\n"; print chgSpace($line); sub chgSpace { my $line = shift; my ( $spaces ) = $line =~ /^(\s+)/; $spaces =~ s/ /_/g; $line =~ s/^\s+/$spaces/; return $line; }

Re: Search & Replace

2001-12-18 Thread Jonathan E. Paton
> Hi, > > I am used to work with a search and replace software > and I have a list of pattern like the one above which > I would like to translate to PERL. Need your help and > comments. > There is an example above? I'm assuming your Austrailian, since that'd mean you'd be upside down compare

Re: Search --> Replace on Unix

2001-09-12 Thread lc-brian_d_foy
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (John W. Krahn) wrote: > brian d foy wrote: > > In article <[EMAIL PROTECTED]>, > > [EMAIL PROTECTED] (David Gilden) wrote: > > > perl -e 'foreach $file (glob("*")) {grep '../forum_idx.pl' >'../cgi-bin/forum_idx.pl');}' > > perl -pi.old -

Re: Search --> Replace on Unix

2001-09-06 Thread John W. Krahn
Brian D Foy wrote: > > In article <[EMAIL PROTECTED]>, > [EMAIL PROTECTED] (David Gilden) wrote: > > > perl -e 'foreach $file (glob("*")) {grep '../forum_idx.pl' >'../cgi-bin/forum_idx.pl');}' > > you just want to go through each file and replace those instances? > > perl -pi.old -e "s|..

Re: Search --> Replace on Unix

2001-09-06 Thread brian d foy
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (David Gilden) wrote: > perl -e 'foreach $file (glob("*")) {grep '../forum_idx.pl' >'../cgi-bin/forum_idx.pl');}' you just want to go through each file and replace those instances? perl -pi.old -e "s|../forum_idx.pl|../cgi-bin/forum_idx.pl