perl -pi.bak -e equivalent

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Caj Zell

    #1

    perl -pi.bak -e equivalent

    Hello,

    I am looking a little bit at python and am curious of one thing I
    often use in perl. Suppose, I want to change the string
    "best_compo ser" to "Zappa" in a document called facts.txt, then in
    perl I would do

    perl -pi.bak -e "s/best_composer/Zappa/;" facts.txt

    Can I do that with python from the command line so easily?

    Caj Zell
  • Diez B. Roggisch

    #2
    Re: perl -pi.bak -e equivalent

    Caj Zell wrote:
    [color=blue]
    > Hello,
    >
    > I am looking a little bit at python and am curious of one thing I
    > often use in perl. Suppose, I want to change the string
    > "best_compo ser" to "Zappa" in a document called facts.txt, then in
    > perl I would do
    >
    > perl -pi.bak -e "s/best_composer/Zappa/;" facts.txt
    >
    > Can I do that with python from the command line so easily?[/color]

    Short answer: No. Perl is designed for this kind of stuff. Python won't
    catch up in that field, for various reasons. There have been plenty of
    discussions on the subject of one-liners in python - googl.groups will show
    you to them.

    As always, its important to use the right tool for the job - and in this
    case, I'd even go for sed :)

    sed s/best_composer/Zappa/ < facts.txt > pi.bak

    is even shorter...

    --
    Regards,

    Diez B. Roggisch

    Comment

    • gabriele renzi

      #3
      Re: perl -pi.bak -e equivalent

      Diez B. Roggisch ha scritto:
      [color=blue]
      > Caj Zell wrote:
      >
      >[color=green]
      >>Hello,
      >>
      >>I am looking a little bit at python and am curious of one thing I
      >>often use in perl. Suppose, I want to change the string
      >>"best_compose r" to "Zappa" in a document called facts.txt, then in
      >>perl I would do
      >>
      >>perl -pi.bak -e "s/best_composer/Zappa/;" facts.txt
      >>
      >>Can I do that with python from the command line so easily?[/color]
      >
      >
      > Short answer: No. Perl is designed for this kind of stuff. Python won't
      > catch up in that field, for various reasons. There have been plenty of
      > discussions on the subject of one-liners in python - googl.groups will show
      > you to them.
      >
      > As always, its important to use the right tool for the job - and in this
      > case, I'd even go for sed :)
      >
      > sed s/best_composer/Zappa/ < facts.txt > pi.bak
      >
      > is even shorter...[/color]

      let me suggest pyone:


      It is really an erethic twist of python, anyway

      PS
      the perl code does not do the same thing than the sed one, it creates a
      backup file named facts.txt.bak and changes facts.txt

      Comment

      • Caj Zell

        #4
        Re: perl -pi.bak -e equivalent

        "Diez B. Roggisch" <deetsNOSPAM@we b.de> wrote in message news:<cnngpb$qt m$05$3@news.t-online.com>...[color=blue]
        > Caj Zell wrote:
        >[color=green]
        > > Hello,
        > >
        > > I am looking a little bit at python and am curious of one thing I
        > > often use in perl. Suppose, I want to change the string
        > > "best_compo ser" to "Zappa" in a document called facts.txt, then in
        > > perl I would do
        > >
        > > perl -pi.bak -e "s/best_composer/Zappa/;" facts.txt
        > >
        > > Can I do that with python from the command line so easily?[/color]
        >
        > Short answer: No. Perl is designed for this kind of stuff. Python won't
        > catch up in that field, for various reasons. There have been plenty of
        > discussions on the subject of one-liners in python - googl.groups will show
        > you to them.[/color]


        OK, I did some googling on "perl command line -e python equivalent"
        and various combinations, but didn't think of the obvious "perl
        one-liner python equivalent" your answer implies. With that I want to
        say that I did try before posting here.

        Nice to see noone challenges the musical meaning of my search and
        replace example, seems like you pythoners have pretty good taste.

        Caj Zell

        Comment

        Working...