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

Discussion in 'Perl Misc' started by Hike Mike, Jul 22, 2005.

  1. Hike Mike

    Hike Mike Guest

    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
     
    Hike Mike, Jul 22, 2005
    #1
    1. Advertising

  2. Hike Mike

    Paul Lalli Guest

    Re: perform substitutions listed in a file on a path

    Hike Mike wrote:
    > 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
     
    Paul Lalli, Jul 22, 2005
    #2
    1. Advertising

  3. Hike Mike

    James Taylor Guest

    In article <>,
    Hike Mike <> wrote:
    >
    > 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.

    --
    James Taylor, London, UK PGP key: 3FBE1BF9
    To protect against spam, the address in the "From:" header is not valid.
    In any case, you should reply to the group so that everyone can benefit.
    If you must send me a private email, use james at oakseed demon co uk.
     
    James Taylor, Jul 22, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. fripper
    Replies:
    5
    Views:
    1,119
    Juan T. Llibre
    Oct 28, 2005
  2. Jason Heyes
    Replies:
    4
    Views:
    380
    Karl Heinz Buchegger
    Mar 24, 2005
  3. Tony Eva
    Replies:
    1
    Views:
    481
    Jeff Epler
    Nov 9, 2003
  4. Jim in Arizona
    Replies:
    0
    Views:
    730
    Jim in Arizona
    May 8, 2009
  5. perl_newbie
    Replies:
    0
    Views:
    91
    perl_newbie
    Jun 2, 2005
Loading...

Share This Page