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

Discussion in 'Perl Misc' started by lucy, Sep 1, 2004.

  1. lucy

    lucy Guest

    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.
    lucy, Sep 1, 2004
    #1
    1. Advertising

  2. "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
    Scott Seidman, Sep 1, 2004
    #2
    1. Advertising

  3. Re: A question about Perl: using perl command line to replacestrings...

    [ 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.
    Scott W Gifford, Sep 1, 2004
    #3
  4. 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
    Gunnar Hjalmarsson, Sep 1, 2004
    #4
  5. lucy

    lucy Guest

    "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
    lucy, Sep 1, 2004
    #5
  6. lucy

    lucy Guest

    "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...?
    lucy, Sep 1, 2004
    #6
  7. lucy

    Anno Siegel Guest

    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
    Anno Siegel, Sep 2, 2004
    #7
  8. lucy

    Joe Smith Guest

    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
    Joe Smith, Sep 3, 2004
    #8
    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. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    732
    Malcolm
    Jun 24, 2006
  2. anonym
    Replies:
    1
    Views:
    999
    Knute Johnson
    Jan 15, 2009
  3. D. Alvarado

    command line search and replace dilemma

    D. Alvarado, Sep 11, 2004, in forum: Perl Misc
    Replies:
    5
    Views:
    136
    Uri Guttman
    Sep 11, 2004
  4. Anthony Roy
    Replies:
    7
    Views:
    207
    A. Sinan Unur
    Mar 4, 2005
  5. Ting Wang
    Replies:
    3
    Views:
    185
    Paul Lalli
    Dec 13, 2005
Loading...

Share This Page