Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > A question about Perl: using perl command line to replace strings...

Reply
Thread Tools

A question about Perl: using perl command line to replace strings...

 
 
lucy
Guest
Posts: n/a
 
      09-01-2004
I have a quick question, how to change a string "abcd" to another string
"xyabcd" in all the *.m (text) files under current directory?

I defintely can write a perl script to do this. But I remember there is a
most simple way of doing this using Perl.

It is just "Perl xxxxxxxxxxxxxxxx" a command line with some options...

It just escaped my memory, anybody knows how to do that please give me a
hand!

Thanks a lot.


 
Reply With Quote
 
 
 
 
Scott Seidman
Guest
Posts: n/a
 
      09-01-2004
"lucy" <> wrote in
news:ch550l$j1t$:

> I have a quick question, how to change a string "abcd" to another
> string "xyabcd" in all the *.m (text) files under current directory?
>
> I defintely can write a perl script to do this. But I remember there
> is a most simple way of doing this using Perl.
>
> It is just "Perl xxxxxxxxxxxxxxxx" a command line with some options...
>
> It just escaped my memory, anybody knows how to do that please give me
> a hand!
>
> Thanks a lot.
>
>
>


You still need to figure out what xxxxxxxxxxx is-- why not just put it in a
file and be done with it? It's going to be the same loop through the
directories in your file, the same search and replace statement, and the
same output commands.

Scott
 
Reply With Quote
 
 
 
 
Scott W Gifford
Guest
Posts: n/a
 
      09-01-2004
[ Why was this crossposted to comp.soft-sys.matlab? ]

"lucy" <> writes:

> I have a quick question, how to change a string "abcd" to another string
> "xyabcd" in all the *.m (text) files under current directory?


perl -pi.bak -e's/abcd/xyabcd/g' *.m

See the docs for the -i flag in perlrun(1) for more information.

----ScottG.
 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      09-01-2004
lucy wrote:
> I have a quick question,
> ...
> I defintely can write a perl script to do this. But I remember
> there is a most simple way of doing this using Perl.
>
> It is just "Perl xxxxxxxxxxxxxxxx" a command line with some
> options...
>
> It just escaped my memory,


And the first thing you came to think of was asking lots of people (in
two!! newsgroups) for help.

> anybody knows how to do that please give me a hand!


Give you a hand with what? Looking it up in and reading the docs for
you??

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
lucy
Guest
Posts: n/a
 
      09-01-2004

"Scott W Gifford" <> wrote in message
news:...
>[ Why was this crossposted to comp.soft-sys.matlab? ]
>
> "lucy" <> writes:
>
>> I have a quick question, how to change a string "abcd" to another string
>> "xyabcd" in all the *.m (text) files under current directory?

>
> perl -pi.bak -e's/abcd/xyabcd/g' *.m
>
> See the docs for the -i flag in perlrun(1) for more information.
>
> ----ScottG.


That's great! That's exactly I want. But how can I make this work for all
subdirectories recursively?

thanks a lot


 
Reply With Quote
 
lucy
Guest
Posts: n/a
 
      09-01-2004

"lucy" <> wrote in message
news:ch5bgv$rs3$...
>
> "Scott W Gifford" <> wrote in message
> news:...
>>[ Why was this crossposted to comp.soft-sys.matlab? ]
>>
>> "lucy" <> writes:
>>
>>> I have a quick question, how to change a string "abcd" to another string
>>> "xyabcd" in all the *.m (text) files under current directory?

>>
>> perl -pi.bak -e's/abcd/xyabcd/g' *.m
>>
>> See the docs for the -i flag in perlrun(1) for more information.
>>
>> ----ScottG.

>
> That's great! That's exactly I want. But how can I make this work for all
> subdirectories recursively?
>
> thanks a lot
>


And how to make it work even for filenames and directory names...?


 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      09-02-2004
lucy <> wrote in comp.lang.perl.misc:
>
> "lucy" <> wrote in message
> news:ch5bgv$rs3$...
> >
> > "Scott W Gifford" <> wrote in message
> > news:...
> >>[ Why was this crossposted to comp.soft-sys.matlab? ]
> >>
> >> "lucy" <> writes:
> >>
> >>> I have a quick question, how to change a string "abcd" to another string
> >>> "xyabcd" in all the *.m (text) files under current directory?
> >>
> >> perl -pi.bak -e's/abcd/xyabcd/g' *.m
> >>
> >> See the docs for the -i flag in perlrun(1) for more information.
> >>
> >> ----ScottG.

> >
> > That's great! That's exactly I want. But how can I make this work for all
> > subdirectories recursively?
> >
> > thanks a lot
> >

>
> And how to make it work even for filenames and directory names...?


Want it to milk the cows in the morning too?

Anno
 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      09-03-2004
lucy wrote:

> That's great! That's exactly I want. But how can I make this work for all
> subdirectories recursively?


Put the one-liner into a sub in a file, and 'use File::Find;'.
-Joe
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to replace command.com with my version of command.com ? bas Computer Support 4 12-01-2006 01:12 AM
use one line Perl command to add a line at the begin of a file Ting Wang Perl Misc 3 12-13-2005 06:07 PM
Pull out only first field of ps command ( in Perl ) PERL RUN COMMAND tweetiebirds@gmail.com Perl Misc 2 03-26-2005 06:03 AM
Passing in the replace string for a regex via the command line -HOW? Anthony Roy Perl Misc 7 03-04-2005 09:28 PM
command line search and replace dilemma D. Alvarado Perl Misc 5 09-11-2004 08:01 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57