[command processing -e] perform substitutions listed in a file on a path

H

Hike Mike

I want to replace strings in a file called .classpath

so i do this:

perl -pi.bak -e "s/ptlEdgeAth/ptlAthEdge/g" .classpath

and it works.

I want to replace strings in all files called .classpath (incuding
sub-directories)

so i do this:

find -name .classpath | xargs perl -pi.bak -e
"s/ptlEdgeAth/ptlAthEdge/g"
and it works.

How do i read a list of substitutions from a file and apply them to all
files named .classpath in all subdirectories?

I tried this:
find -name .classpath | xargs perl -pi.bak -e "diff.txt"

where diff.txt contains the lines:
s/ptlEdgeAth/ptlAthEdge/g
s/ptlEdgeAthDb/ptlAthEdgeDb/g
s/ptlEdgeCore/ptlCoreEdge/g

but it doesn't work
 
P

Paul Lalli

Hike said:
How do i read a list of substitutions from a file and apply them to all
files named .classpath in all subdirectories?

I tried this:
find -name .classpath | xargs perl -pi.bak -e "diff.txt"

where diff.txt contains the lines:
s/ptlEdgeAth/ptlAthEdge/g
s/ptlEdgeAthDb/ptlAthEdgeDb/g
s/ptlEdgeCore/ptlCoreEdge/g

You're asking perl to execute the code "diff.txt". But what you meant
to do is ask perl to execute the code contained in the file diff.txt
In other words, you don't want the -e option. You just want to execute
that file.

find -name .classpath | xargs perl -pi.bak diff.txt

Paul Lalli
 
J

James Taylor

I tried this:
find -name .classpath | xargs perl -pi.bak -e "diff.txt"

You don't want the -e unless "diff.txt" is a Perl statement I
don't recognise. The quotes are unnecessary too.
where diff.txt contains the lines:
s/ptlEdgeAth/ptlAthEdge/g
s/ptlEdgeAthDb/ptlAthEdgeDb/g
s/ptlEdgeCore/ptlCoreEdge/g

You'd better put semicolons at the end of each line too.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top