in reply to Lost in-place file edit code

Like this?

perl -pi.bak -e "s/ /_/;" infile.txt

See perlrun. For an on-site reference, see Re: One Liners (warning, I wrote that node).


Dave

Updated: fixed '-e'

Replies are listed 'Best First'.
Re^2: Lost in-place file edit code
by monarch (Priest) on Jun 08, 2005 at 05:37 UTC
    Surprisingly I also had exactly the same deja vu type experience a couple of days ago. And as quoted above, the -p command loops through text executing the command you give, and printing the result. The -i specifies what extension you want to give to your backup files.

    My most recent attempt was a file that looked like this:

    #!/usr/bin/perl -i.orig -p s/submit_(.*?)_/submit\u$1/g;

    I love the way you can specify command line arguments on the hash-bang line. The code above used the in-place capitalisation regexp operator discussed in another recent node (Regexp matched part to lower case).

Re^2: Lost in-place file edit code
by GrandFather (Saint) on Jun 08, 2005 at 05:33 UTC
    Nope, it was a few lines of code. Although I seem to remember seeing that described in the same context.

    Food for thought, not fuel for flames.

      Hi,

      You might of seen it in FMTYEWTK About Mass Edits In Perl or perlrun

      HTH.

      Walking the road to enlightenment... I found a penguin and a camel on the way.....
      Fancy a yourname@perl.me.uk? Just ask!!!