Re: Replace words in a file using perl script

2011-12-16 Thread Brandon McCaig
On Thu, Dec 15, 2011 at 07:36:37AM -0800, Melvin wrote: > Hi, Hello: > I was trying to write a script to replace baby to bigboy in a file:- > However the below script doesn't work Could someone help me??? > > #!/usr/bin/perl -w > use strict; > > open (FILE_IN , $ARGV[0]) || die ("ERROR: Gimme I

Re: Replace words in a file using perl script

2011-12-16 Thread Uri Guttman
On 12/16/2011 03:23 PM, Chris Stinemetz wrote: Hello Melvin, Give this a try. I used the advice Jim gave and this is what I came up with. It seems to do what you are asking for. #!/usr/bin/perl use warnings; use strict; my $inFile = "input.txt"; my $outFile = "output.txt"; open my $fin, '<',

Re: Replace words in a file using perl script

2011-12-16 Thread Chris Stinemetz
Hello Melvin, Give this a try. I used the advice Jim gave and this is what I came up with. It seems to do what you are asking for. #!/usr/bin/perl use warnings; use strict; my $inFile = "input.txt"; my $outFile = "output.txt"; open my $fin, '<', $inFile or die "ERROR opening $inFile: $!"; open

RE: Replace words in a file using perl script

2011-12-16 Thread Kronheim, David (Contr)
Hi Melvin, It looks like you're editing each line but not writing back to the file, add some print's or say's for $line to see what's happening. Sincerely, David Kronheim Production Support Tier II Gateway Error Correction, VZ450 EDI, EDI Billing, & Metakey/LIA 484-213-1315 __

Re: Replace words in a file using perl script

2011-12-16 Thread Jim Gibson
On 12/15/11 Thu Dec 15, 2011 7:36 AM, "Melvin" scribbled: > Hi, > > I am a Perl baby :-) > > I was trying to write a script to replace baby to bigboy in a file:- > However the below script doesn't work Could someone help me??? The problem with your script is that you are not writing out the

Re: Replace digit by equivalent in words.

2010-10-12 Thread Jon Hermansen
Hi Pawan, For converting integers to their English equivalents, use Lingua::En::Inflect. # http://search.cpan.org/~dconway/Lingua-EN-Inflect-1.892/lib/Lingua/EN/Inflect.pm#CONVERTING_NUMBERS_TO_WORDS On Tue, Oct 12, 2010 at 8:16 PM, pawan kumar wrote: > Hi Folks, > I need an help.I

Re: Replace System("Dir") call Help

2009-06-21 Thread Telemachus
On Sun Jun 21 2009 @ 7:40, AndrewMcHorney wrote: > Hello > > I have written a perl script and I am in the debugging and imroving the > code. The first improvement is want to make is to replace the > system("Dir c:/s") call because it is not portable. So I was told to use > the File package.

Re: Replace pattern with a variable num of spaces

2009-06-18 Thread John W. Krahn
Steve Bertrand wrote: John W. Krahn wrote: Steve Bertrand wrote: +sub is_word ($) { +return unless defined $_[0] && $_[0] ne ''; +return if $_[0] =~ /[\w\s]+/; +return 1; +} The other is_* functions in that module use anchors with their regular expressions so you probably should

Re: Replace pattern with a variable num of spaces

2009-06-18 Thread Steve Bertrand
John W. Krahn wrote: > Steve Bertrand wrote: >> I wasted about two hours of my coding time trying to come up with a >> special JAPH, but I just haven't been able to make map() do what I think >> it should do ;) > > What did you think it should do? What did you want it to do? Originally, I was t

Re: Replace pattern with a variable num of spaces

2009-06-17 Thread John W. Krahn
Steve Bertrand wrote: John W. Krahn wrote: Steve Bertrand wrote: [ snip ] In the third line of the following code, I want the replacement pattern to be (whitespace * $_[1]). I'll deal with the undef issue after I figure out how to use {$num} on essentially nothing. I haven't been able to make

Re: Replace pattern with a variable num of spaces

2009-06-17 Thread Steve Bertrand
John W. Krahn wrote: > Steve Bertrand wrote: [ snip ] >> In the third line of the following code, I want the replacement pattern >> to be (whitespace * $_[1]). I'll deal with the undef issue after I >> figure out how to use {$num} on essentially nothing. I haven't been able >> to make it work with

Re: Replace pattern with a variable num of spaces

2009-06-17 Thread John W. Krahn
Steve Bertrand wrote: I'm attempting to write a patch for a module that I feel I can use within one of my own modules, and I've run into something that I can't solve (I can't come up with the proper query in Google). Perhaps code will help here. First, I know 'word' does not include whitespace,

Re: Replace string with list of strings via character changes

2009-04-12 Thread Dr.Ruud
Kelly Jones wrote: I want to ASCII-ify the geonames alternatenames table using iso-8859-1. Also try Text::Unidecode. -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: Replace string with list of strings via character changes

2009-04-11 Thread Kelly Jones
Thanks, David. I figured out how to do this recursively. Hopefully the code beow will clarify my question, even though I no longer need an answer. sub translit { my($str) = @_; my($oth) = $str; my(@res); # obviously, this could be improved to not hardcode o->xy, a->uv if ($str=~/o/) {

RE: Replace string with list of strings via character changes

2009-04-10 Thread Wagner, David --- Senior Programmer Analyst --- CFS
> -Original Message- > From: Kelly Jones [mailto:kelly.terry.jo...@gmail.com] > Sent: Friday, April 10, 2009 13:33 > To: beginners@perl.org > Subject: Replace string with list of strings via character changes > > I want to replace all the o's in a string with x's or y's and all the > a's

Re: replace text in file

2009-02-25 Thread Jim Gibson
On 2/25/09 Wed Feb 25, 2009 5:02 PM, "lemba" scribbled: > Hi All, > > I'm trying to replace some text in file. Below is my script. It > basically makes a copy of line with changes. How can I replace pattern > in the uxix sed way? I don't use sed, but you can use Perl "one-liners" to emulate s

Re: Replace a specific block of data

2008-10-27 Thread Brian
Jay Savage wrote: On Mon, Oct 27, 2008 at 7:32 AM, Brian <[EMAIL PROTECTED]> wrote: Hello again Not too sure how to pose this question, but here goes. Working on an html page. There are many blocks of code placed between and in the page. The block(s) I am playing with have seven lines of co

Re: Replace a specific block of data

2008-10-27 Thread Jay Savage
On Mon, Oct 27, 2008 at 7:32 AM, Brian <[EMAIL PROTECTED]> wrote: > Hello again > > Not too sure how to pose this question, but here goes. > > Working on an html page. > There are many blocks of code placed between and in the page. > > The block(s) I am playing with have seven lines of code place

Re: Replace first 2 bytes on binary files?

2008-10-05 Thread Dr.Ruud
"John W. Krahn" schreef: > Dr.Ruud: >> Mr. Shawn H. Corey: >>> Louise Hoffman: I would like to replace the first 2 bytes from ## to BM in all the files in a directory. The files are binary. >>> >>> Use glob to get the list of files. Use open with read-write to read >>> the first line a

Re: Replace first 2 bytes on binary files?

2008-10-05 Thread John W. Krahn
Dr.Ruud wrote: "Mr. Shawn H. Corey" schreef: Louise Hoffman: I would like to replace the first 2 bytes from ## to BM in all the files in a directory. The files are binary. Use glob to get the list of files. Use open with read-write to read the first line and replace the bytes. I wouldn't

Re: Replace first 2 bytes on binary files?

2008-10-05 Thread Dr.Ruud
"Mr. Shawn H. Corey" schreef: > Louise Hoffman: >> I would like to replace the first 2 bytes from ## to BM in all the >> files in a directory. The files are binary. > > Use glob to get the list of files. Use open with read-write to read > the first line and replace the bytes. I wouldn't read a "

Re: Replace first 2 bytes on binary files?

2008-10-05 Thread Mr. Shawn H. Corey
On Sun, 2008-10-05 at 04:44 -0700, Louise Hoffman wrote: > Dear programmers > > I am new to Perl, and was wondering, if someone could help me? > > I would like to replace the first 2 bytes from ## to BM in all the > files in a directory. The files are binary. > > Can that be done easily in Perl?

Re: Replace ISO entities

2008-09-23 Thread Vyacheslav Karamov
Vyacheslav Karamov пишет: Jeff Pang пишет: 2008/9/22 Vyacheslav Karamov <[EMAIL PROTECTED]>: Hi All! Jow to replace ISO entities (like "é") or four-character Unicode entities (like "Ǖ") with Unicode characters? use Encode; see perldoc Encode, which is a built-in Perl module.

Re: Replace ISO entities

2008-09-23 Thread Vyacheslav Karamov
Jeff Pang пишет: 2008/9/22 Vyacheslav Karamov <[EMAIL PROTECTED]>: Hi All! Jow to replace ISO entities (like "é") or four-character Unicode entities (like "Ǖ") with Unicode characters? use Encode; see perldoc Encode, which is a built-in Perl module. Hi All! I saw perldoc Enc

Re: Replace ISO entities

2008-09-22 Thread Jeff Pang
2008/9/22 Vyacheslav Karamov <[EMAIL PROTECTED]>: > Hi All! > > Jow to replace ISO entities (like "é") or four-character Unicode > entities (like "Ǖ") with Unicode characters? > use Encode; see perldoc Encode, which is a built-in Perl module. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For ad

Re: replace chars

2007-12-27 Thread yitzle
On Dec 27, 2007 11:46 AM, Octavian Rasnita <[EMAIL PROTECTED]> wrote: > I am thinking to do something like: > ...because it requires less code. > More legible code is usually far more valuable than shorter code.

Re: replace chars

2007-12-27 Thread Octavian Rasnita
From: "Gunnar Hjalmarsson" <[EMAIL PROTECTED]> This is the approach I had in mind: $ cat test.pl #!/usr/bin/perl use Encode; $octets = ; $chars = decode 'utf8', $octets; %special = ( "\xc3\x96" => 'O', "\xc3\xa5" => 'a' ); ($translated = $octets) =~ s/(\xc3\x96|\xc3\xa5)/$special{$1}/g; prin

Re: replace chars

2007-12-27 Thread Octavian Rasnita
From: "rahed" <[EMAIL PROTECTED]> [EMAIL PROTECTED] ("Octavian Rasnita") writes: I want to replace some special characters with their corresponding Western European chars, for example a with a, â with a, s with s, t with t, î with i and so on. The module Text::Unidecode does exactly what you

Re: replace chars

2007-12-27 Thread rahed
[EMAIL PROTECTED] ("Octavian Rasnita") writes: > I want to replace some special characters with their corresponding > Western European chars, for example a with a, â with a, s with s, t > with t, î with i and so on. The module Text::Unidecode does exactly what you look for. The conversion is not

Re: replace chars

2007-12-27 Thread Octavian Rasnita
From: "Dr.Ruud" <[EMAIL PROTECTED]> "Octavian Rasnita" schreef: I have also seen that length($string) returns the number of bytes of $string, and not the number of chars (if the string contains UTF-8 chars). This tells me that you are taking input from an octet buffer that comes from outside.

Re: replace chars

2007-12-27 Thread Gunnar Hjalmarsson
Chas. Owens wrote: On Dec 26, 2007 2:59 PM, Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote: Well, then you'll probably need to identify the utf8 octet sequences that correspond to the special characters you want to see transformed. snip Perl strings are in UTF-8*, but if you want to specify a ch

Re: replace chars

2007-12-26 Thread Dr.Ruud
"Octavian Rasnita" schreef: > I have also seen that length($string) returns the number of bytes of > $string, and not the number of chars (if the string contains UTF-8 > chars). This tells me that you are taking input from an octet buffer that comes from outside. my $octets = <>; my $str

Re: replace chars

2007-12-26 Thread Octavian Rasnita
From: "Chas. Owens" <[EMAIL PROTECTED]> >> I believe the OP will need to identify all the characters he would >> like >> to see converted, and code the conversion rules himself using the >> tr/// >> or s/// operator. > > Yes I think that it might not be any standard transforming algorithm > f

Re: replace chars

2007-12-26 Thread Chas. Owens
On Dec 26, 2007 2:59 PM, Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote: > [ Please only quote what's necessary to give context. ] > [ Please don't top-post. ] > > Octavian Rasnita wrote: > > Gunnar Hjalmarsson wrote: > >> I believe the OP will need to identify all the characters he would like > >> t

Re: replace chars

2007-12-26 Thread Gunnar Hjalmarsson
[ Please only quote what's necessary to give context. ] [ Please don't top-post. ] Octavian Rasnita wrote: Gunnar Hjalmarsson wrote: I believe the OP will need to identify all the characters he would like to see converted, and code the conversion rules himself using the tr/// or s/// operator.

Re: replace chars

2007-12-26 Thread Tom Phoenix
On Dec 26, 2007 9:33 AM, Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote: > Tom Phoenix wrote: > > You might be able to do what you want with Encode. > > > > http://perldoc.perl.org/Encode.html > > Might he? How? If what he wants is within the abilities of that module, of course. It may be that

Re: replace chars

2007-12-26 Thread Octavian Rasnita
won't have any issues, because the chars are UTF-8. Thanks. Octavian - Original Message - From: "Gunnar Hjalmarsson" <[EMAIL PROTECTED]> To: Sent: Wednesday, December 26, 2007 7:33 PM Subject: Re: replace chars Tom Phoenix wrote: On Dec 26, 2007 3:05 AM, Octavian

Re: replace chars

2007-12-26 Thread Gunnar Hjalmarsson
Tom Phoenix wrote: On Dec 26, 2007 3:05 AM, Octavian Rasnita <[EMAIL PROTECTED]> wrote: I want to replace some special characters with their corresponding Western European chars, for example a with a, â with a, s with s, t with t, î with i and so on. I thought that all those characters were in

Re: replace chars

2007-12-26 Thread Tom Phoenix
On Dec 26, 2007 3:05 AM, Octavian Rasnita <[EMAIL PROTECTED]> wrote: > I want to replace some special characters with their corresponding Western > European chars, for example a with a, â with a, s with s, t with t, î with i > and so on. > > Could you please recommend a module that can do this? Y

Re: replace existing text within multiple text files: How?

2007-09-11 Thread Xavier Noria
On Sep 11, 2007, at 10:05 PM, Gerald Wheeler wrote: Correct That can be done with a one-liner: perl -0777 -pi.bak -e '$_ = q{new text goes here}' *.txt The options -p, -i, and -e are documented in perlrun. The flag -0777 has the side-effect of slurping the whole file into $_ (one file at

Re: replace existing text within multiple text files: How?

2007-09-11 Thread Chas Owens
On 9/11/07, Gerald Wheeler <[EMAIL PROTECTED]> wrote: > I have about 400 text files I need to replace the contents. All files > are in the current directory as the perl script runs out of snip What you need to do depends heavily on what you mean by "replace the contents". In general you can get a

Re: replace existing text within multiple text files: How?

2007-09-11 Thread Xavier Noria
On Sep 11, 2007, at 9:43 PM, Gerald Wheeler wrote: I have about 400 text files I need to replace the contents. All files are in the current directory as the perl script runs out of my $newText = "This is my new text.. anybody's text goes here"; open(INFILE, $plants) while (<>) { print $ne

RE: replace multiple tokens

2006-08-30 Thread Moon, John
Thank you Robin & John for the help Jwm... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: replace multiple tokens

2006-08-25 Thread John W. Krahn
Moon, John wrote: > I have the follows code > perl -e ' > @a=(q{a...x name=taga_1 #...d name=tagb_1 f...r name=tagc_1 xxnn}, > q{h...e name=taga_4 t...g name=tagb_4 k name=tagc_4 nn}); > $ndx = 0; > foreach $ln (@a) { > print "b4 = $ln\n"; > $ln =~s/(name=.*)\d+/\1$ndx/g; You should u

Re: replace multiple tokens

2006-08-25 Thread Robin Norwood
"Moon, John" <[EMAIL PROTECTED]> writes: > I have the follows code > perl -e ' > @a=(q{a...x name=taga_1 #...d name=tagb_1 f...r name=tagc_1 xxnn}, > q{h...e name=taga_4 t...g name=tagb_4 k name=tagc_4 nn}); > $ndx = 0; > foreach $ln (@a) { > print "b4 = $ln\n"; > $ln =~s/(name=.*)\d+

Re: replace all # chars in a text where the first with and second in through the text

2006-08-11 Thread Dr.Ruud
"Steven De Ketelaere" schreef: > I want to replace all first # characters with > and second # characters with [...] > > If only 1 # character is found I do not need to replace this s{#([^#]*)#}{$1}g -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] F

Re: Replace only once.

2005-12-05 Thread mohd sharif
But it will fail if we have spaces before $modtager = " 45247"; You should probably write like this. #!/usr/bin/perl $modtager = "45247"; $modtager =~ s/^\s+//g; # deletes all leading spaces in variable $modtager =~ s/^(45)//; # guarantees match of 45 -Sharif On 12/2/05, Alexandre Checin

Re: Replace only once.

2005-12-02 Thread Alexandre Checinski
unless you use this syntax : $modtager =~s/45//g; only the first occurence of the searched string will be replace... so what you wrote should work fine... BR Mads N. Vestergaard wrote: Hi Everybody, I have a script where I need to replace 45 in the beginning, with nothing in a variable...

Re: Replace only once.

2005-12-02 Thread Alois Heuboeck
On Fri, Dec 02, 2005 at 10:22:47AM +, Mads N. Vestergaard wrote: I have a script where I need to replace 45 in the beginning, with nothing in a variable It looks like this: #!/usr/bin/perl $modtager = "45247"; $modtager =~s/45//; Then $modtager is 247, but if forinstance the

Re: Replace only once.

2005-12-02 Thread Paul Johnson
On Fri, Dec 02, 2005 at 10:22:47AM +, Mads N. Vestergaard wrote: > I have a script where I need to replace 45 in the beginning, with nothing > in a variable > > It looks like this: > > #!/usr/bin/perl > > $modtager = "45247"; > > $modtager =~s/45//; > > Then $modtager is 247, but i

Re: replace string ?

2004-08-23 Thread Gunnar Hjalmarsson
Shu Hung wrote: > Is there any function for us to replace a specific string with > another? perldoc -f substr -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

RE: Replace tab delimited headings in file

2004-06-17 Thread Debbie Cooper
EMAIL PROTECTED] Subject: Re: Replace tab delimited headings in file On Jun 16, Debbie Cooper said: >I need to replace the tab delimited headings in a text file so that I end up >with shorter (lengthwise) headings. I have headings like the following: > >Heading_1,122 Heading_2,122 Another

Re: Replace tab delimited headings in file

2004-06-16 Thread Jeff 'japhy' Pinyan
On Jun 16, Debbie Cooper said: >I need to replace the tab delimited headings in a text file so that I end up >with shorter (lengthwise) headings. I have headings like the following: > >Heading_1,122 Heading_2,122 AnotherHeading_1,1 .. I'm assuming this will be the *first* line of a fil

Re: Replace ' ???

2004-04-27 Thread John W. Krahn
Lonewolf wrote: > > I have a function and can't seem to get this figured out. I have > apostrohe's in the file that I am pulling down, however I need to remove all > of the apostrophe's from the file before putting the file into the system. > > >$fields[0] =~ s/'//; > > > The apostrophe c

Re: Replace ' ???

2004-04-27 Thread James Edward Gray II
On Apr 27, 2004, at 8:23 AM, LoneWolf wrote: I have a function and can't seem to get this figured out. I have apostrohe's in the file that I am pulling down, however I need to remove all of the apostrophe's from the file before putting the file into the system. $fields[0] =~ s/'//; The ap

RE: Replace ' ???

2004-04-27 Thread West, William M
> >I have a function and can't seem to get this figured out. I have >apostrohe's in the file that I am pulling down, however I need to remove >all >of the apostrophe's from the file before putting the file into the system. 1. I'm not sure if ' has to be escaped when in a regex... so try one the

Re: Replace every character

2004-03-23 Thread James Edward Gray II
On Mar 23, 2004, at 1:51 PM, juman wrote: That solved my problem :-) Thanks for the help I probably put toomuch thought into solving this simple thing ;-) Glad to hear it. If you learned something, it was worth the effort. Next time though, post your code so we can help guide you to what you

Re: Replace every character

2004-03-23 Thread juman
That solved my problem :-) Thanks for the help I probably put toomuch thought into solving this simple thing ;-) /juman On Tue, Mar 23, 2004 at 01:29:42PM -0600, James Edward Gray II wrote: > On Mar 23, 2004, at 1:23 PM, juman wrote: > > >Okay thanks :) > > > >Here is a code snippet : > > > >

Re: Replace every character

2004-03-23 Thread James Edward Gray II
On Mar 23, 2004, at 1:23 PM, juman wrote: Okay thanks :) Here is a code snippet : if ($nr == $quiz_id{"$quizzer"}) { $window->print ("Id answer : $reply", MSGLEVEL_NEVER) if ($window); $exit = 0; } elsif ( '$question' == '$quiz_question{"$quizzer"}' ) {

Re: Replace every character

2004-03-23 Thread juman
Okay thanks :) Here is a code snippet : if ($nr == $quiz_id{"$quizzer"}) { $window->print ("Id answer : $reply", MSGLEVEL_NEVER) if ($window); $exit = 0; } elsif ( '$question' == '$quiz_question{"$quizzer"}' ) { $window->print ("Quiz answer : $re

Re: Replace every character

2004-03-23 Thread James Edward Gray II
On Mar 23, 2004, at 11:08 AM, juman wrote: Okey here we go :) I have a text string that can be looking something like this : Language: French -> Swedish: Fille ? And then I have another text that can look just about like anything and I want to compare the two strings. But the symbols > and ? ma

Re: Replace every character

2004-03-23 Thread James Edward Gray II
On Mar 23, 2004, at 10:07 AM, juman wrote: Hmmm this just seems to return 1. Doesn't m/ just meen to match the expression? Yes it does and yes it does. Give me an example of how you were using this data in your script and I'll show you how it relates. ;) James -- To unsubscribe, e-mail: [EMAI

Re: Replace every character

2004-03-23 Thread juman
Hmmm this just seems to return 1. Doesn't m/ just meen to match the expression? /juman On Tue, Mar 23, 2004 at 09:40:42AM -0600, James Edward Gray II wrote: > On Mar 23, 2004, at 9:32 AM, juman wrote: > > >Not sure I understand what you say here... > > > >Should I do this then? > > > >$data = "q

Re: Replace every character

2004-03-23 Thread James Edward Gray II
On Mar 23, 2004, at 9:32 AM, juman wrote: Not sure I understand what you say here... Should I do this then? $data = "question?" $newdata = m/\Q$data\E/ I believe you meant: $newdata =~ m/\Q$data\E/; Hope that helps. James Because I couldn't get that to work? /juman On Tue, Mar 23, 2004 at

Re: Replace every character

2004-03-23 Thread juman
Not sure I understand what you say here... Should I do this then? $data = "question?" $newdata = m/\Q$data\E/ Because I couldn't get that to work? /juman On Tue, Mar 23, 2004 at 09:03:15AM -0600, James Edward Gray II wrote: > On Mar 23, 2004, at 8:54 AM, juman wrote: > > >I have a script that

Re: Replace every character

2004-03-23 Thread James Edward Gray II
On Mar 23, 2004, at 8:54 AM, juman wrote: I have a script that handles some text strings. The textstrings in them self I can't control so they can contain characters as ?:>< etc which makes them hard to check through a regexp. So I want to replace alla characters like this: question? => \q\u\e\s\t

Re: Replace every character

2004-03-23 Thread WC -Sx- Jones
juman wrote: I have a script that handles some text strings. The textstrings in them self I can't control so they can contain characters as ?:>< etc which makes them hard to check through a regexp. So I want to replace alla characters like this: question? => \q\u\e\s\t\i\o\n\? I'll give you a hint:

Re: Replace a string in a text file

2004-03-11 Thread Mr Mojo
Thank you to everyone for your help. I have learned a lot! Any your answers were WAY cooler than mine... Greg > perl -pi -e 's/fox/coyote' text_file_name_here.txt > > Is that cool enough? ;) > > James > -- __ Check out the latest SMS services @

Re: Replace a string in a text file

2004-03-10 Thread zsdc
Jayakumar Rajagopal wrote: Use this from unix prompt : sed s/fox/coyote/g test.txt > tmp Hey, this is not [EMAIL PROTECTED] mailing list! ;) -- ZSDC Perl and Systems Security Consulting -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: Replace a string in a text file

2004-03-10 Thread zsdc
Mr Mojo wrote: I have a text file (texst1.txt) that reads: The quick brown fox jumped over the lazy dog. I would like to replace the word fox with coyote. Is there an easier/simpler/cooler way to do this? You can run this from the command line: perl -pi -es/fox/coyote/g test1.txt Or if you w

Re: Replace a string in a text file

2004-03-10 Thread John W. Krahn
James Edward Gray II wrote: > > On Mar 10, 2004, at 12:56 PM, Mr Mojo wrote: > > > > I have a text file (texst1.txt) that reads: > > > > The quick brown fox jumped over the lazy dog. > > > > I would like to replace the word fox with coyote. Is there an > > easier/simpler/cooler way to do this? >

RE: Replace a string in a text file

2004-03-10 Thread Jayakumar Rajagopal
Use this from unix prompt : sed s/fox/coyote/g test.txt > tmp --Jay -Original Message- From: Mr Mojo [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 10, 2004 1:57 PM To: [EMAIL PROTECTED] Subject: Replace a string in a text file Hello, I have a text file (texst1.txt) that reads: The

Re: Replace a string in a text file

2004-03-10 Thread James Edward Gray II
On Mar 10, 2004, at 12:56 PM, Mr Mojo wrote: Hello, I have a text file (texst1.txt) that reads: The quick brown fox jumped over the lazy dog. I would like to replace the word fox with coyote. Is there an easier/simpler/cooler way to do this? #!/usr/bin/perl -w use strict; open (FILE, "test1.

Re: Replace with regular expression

2003-11-14 Thread Ricardo Pichler
Very thanks Jeff and Wiggins, this work perfectly! Regards, Ricardo Pichler - Original Message - From: "Jeff 'japhy' Pinyan" <[EMAIL PROTECTED]> To: "Ricardo Pichler" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Friday, November 14,

Re: Replace with regular expression

2003-11-13 Thread Jeff 'japhy' Pinyan
On Nov 13, Ricardo Pichler said: >I need replace in my string the characters in >upperCase for the same but preceding the simbol +. > >$myName="RicardoPichler"; >s/.../.../g; # to do this return "+Ricardo+Pichler"; > >$myName=~s/[A-Z]/\+[A-Z]/g; You can't use a regex on the right-hand side of a s

Re: Replace with regular expression

2003-11-13 Thread Wiggins d'Anconia
Ricardo Pichler wrote: Hi... I need replace in my string the characters in upperCase for the same but preceding the simbol +. Ex.: $myName="RicardoPichler"; s/.../.../g; # to do this return "+Ricardo+Pichler"; but like this: $myName=~s/[A-Z]/\+[A-Z]/g; but this don´t work. You are attempting to use

Re: replace strings and preserve case

2002-11-06 Thread John W. Krahn
David Garamond wrote: > > is there a short recipe to do this in perl? i want to replace all "die" > with "paint" and preserve case (i.e. "Die" should be replaced by > "Paint", "DIE" by "PAINT", and so on). there's a smart snippet on TPJ to > do this: > > $string =~ s/($x)/"\L$y"^"\L$1"^$1/ie; >

RE: replace

2002-09-12 Thread Timothy Johnson
How about this? $tmpview1 =~ s/\\//g; -Original Message- From: Javeed SAR [mailto:[EMAIL PROTECTED]] Sent: Thursday, September 12, 2002 11:03 PM To: [EMAIL PROTECTED] Subject: replace Hi, I have \\blrk35ed\views\test_merge.vws in a variable $tmpview1 How to replace \

Re: Replace last # with \n

2002-07-23 Thread Jeff 'japhy' Pinyan
On Jul 23, John W. Krahn said: >Rich Busse wrote: >> >> I want to replace the last "#" with a newline. I've come up with a few ideas > >$_ = reverse; >s/#/\n/; >$_ = reverse; Here's a (potential) Perl 5.8.1 way of doing it, which is likely to be faster than the sexeger (reversing approach above)

Re: Replace last # with \n

2002-07-23 Thread John W. Krahn
Rich Busse wrote: > > I have a string that looks like > > Operator Overview#PGM#Report about all configured > operators#/opt/OV/bin/OpC/call_sqlplus.sh all_oper# > > I want to replace the last "#" with a newline. I've come up with a few ideas > like > > substr ($_, rindex ($_, "#"), 1) = "\n"

Re: Replace last # with \n

2002-07-23 Thread Tanton Gibbs
if you want to use s/// you can say s/(.*)#/$1\n/; - Original Message - From: "Busse, Rich" <[EMAIL PROTECTED]> To: "Perl Beginners" <[EMAIL PROTECTED]> Sent: Tuesday, July 23, 2002 9:00 AM Subject: Replace last # with \n > I have a string that looks like > > Operator Overview#PGM#Repor

Re: Replace last # with \n

2002-07-23 Thread Tor Hildrum
<[EMAIL PROTECTED]> wrote: > I have a string that looks like > > Operator Overview#PGM#Report about all configured > operators#/opt/OV/bin/OpC/call_sqlplus.sh all_oper# > > I want to replace the last "#" with a newline. I've come up with a few ideas > like > > substr ($_, rindex ($_, "#"), 1)

Re: Replace

2001-12-20 Thread Andrea Holstein
Shawn wrote: > > > If speed is important, it's good to avoid capturing. > > so $string =~ s/(\w+)_(?:NN|IN|AT)/$1/g; is quicker. > > Is there a big time savings since there is a capture anyway? > It can't be said in generally. It depends on the input and the perl version. But at least, it's alw

Re: Replace

2001-12-20 Thread Shawn
> Shawn wrote: > > > > I think this is what you are asking for... > > > > $string=s/(\w+)_(NN|IN|AT)/$1/g; > > $string=''.$string.''; > > > > Shawn > > I believe, there's a typo :-) > $string =~ s/(\w+)_(NN|IN|AT)/$1/g; > ^ D'OH! Thanks Andrea :-) > > If speed is important, it's g

Re: Replace

2001-12-20 Thread Andrea Holstein
Shawn wrote: > > I think this is what you are asking for... > > $string=s/(\w+)_(NN|IN|AT)/$1/g; > $string=''.$string.''; > > Shawn I believe, there's a typo :-) $string =~ s/(\w+)_(NN|IN|AT)/$1/g; ^ If speed is important, it's good to avoid capturing. so $string =~ s/(\w+)_(?:NN|IN|

Re: Replace

2001-12-19 Thread Shawn
I think this is what you are asking for... $string=s/(\w+)_(NN|IN|AT)/$1/g; $string=''.$string.''; Shawn - Original Message - From: "RNOORY" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, December 19, 2001 1:32 PM Subject: Replace Help to write the replace part of a RE.

Re: replace char n times

2001-12-03 Thread Jeff 'japhy' Pinyan
On Dec 4, Hasanuddin Tamir said: >Taken from perlfaq4, > >s/(_)/++$c <= $count ? '' : $1/ge; Hrm, why not: s/(_)/++$c > $count && $1/ge; since it's DOCUMENTED that > returns '' for false. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother

Re: replace char n times

2001-12-03 Thread Hasanuddin Tamir
On Mon, 3 Dec 2001, Mark Hanson <[EMAIL PROTECTED]> wrote, > Hi gurus! > > I want to use the quantifier {COUNT}? in the following program to remove the first >three underscores. I'm trying to avoid a loop. I have not been able to figure out the >syntax. > > $a = "The_quick_brown_fox_jumped_ov