perlNinny has asked for the wisdom of the Perl Monks concerning the following question:
Let us say that I have a text file with the following:
elephant * -ugly /leave/this/alone
elephant * /only/change/->/turkey
elephant * turkey
I would like to change that file to say:
elephant * -ugly /leave/this/alone
elephant * /only/change/->/fox
elephant * fox
Or a file with:
elephant * -ugly /leave/this/alone
elephant * /only/change/->/turkey
to say:
elephant * -ugly /leave/this/alone
elephant * /only/change/->/fox
Or a file with:
elephant * -ugly /leave/this/alone
elephant * turkey
to say:
elephant * -ugly /leave/this/alone
elephant * fox
As you can see, I need it to change after only an elephant * with either a / or [a-z|A-Z] and only change the last word.
Suggestions?
elephant * -ugly /leave/this/alone
elephant * /only/change/->/turkey
elephant * turkey
I would like to change that file to say:
elephant * -ugly /leave/this/alone
elephant * /only/change/->/fox
elephant * fox
Or a file with:
elephant * -ugly /leave/this/alone
elephant * /only/change/->/turkey
to say:
elephant * -ugly /leave/this/alone
elephant * /only/change/->/fox
Or a file with:
elephant * -ugly /leave/this/alone
elephant * turkey
to say:
elephant * -ugly /leave/this/alone
elephant * fox
As you can see, I need it to change after only an elephant * with either a / or [a-z|A-Z] and only change the last word.
Suggestions?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Changing the contents of a file
by Tanktalus (Canon) on Feb 02, 2006 at 23:13 UTC | |
Re: Changing the contents of a file
by kwaping (Priest) on Feb 02, 2006 at 23:32 UTC | |
Re: Changing the contents of a file
by l3v3l (Monk) on Feb 02, 2006 at 23:16 UTC |
Back to
Seekers of Perl Wisdom