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

L

lucy

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.
 
S

Scott Seidman

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
 
S

Scott W Gifford

[ Why was this crossposted to comp.soft-sys.matlab? ]

lucy said:
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.
 
G

Gunnar Hjalmarsson

lucy said:
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??
 
L

lucy

Scott W Gifford said:
[ Why was this crossposted to comp.soft-sys.matlab? ]

lucy said:
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
 
L

lucy

lucy said:
Scott W Gifford said:
[ Why was this crossposted to comp.soft-sys.matlab? ]

lucy said:
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...?
 
A

Anno Siegel

lucy said:
lucy said:
Scott W Gifford said:
[ Why was this crossposted to comp.soft-sys.matlab? ]


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
 
J

Joe Smith

lucy said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top