Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: s// All Files In Directory

by perl.j (Pilgrim)
on Apr 02, 2012 at 19:47 UTC ( #963102=note: print w/ replies, xml ) Need Help??


in reply to Re: s// All Files In Directory
in thread s// All Files In Directory

I'm not too good with the command line (I'm a Windows guy :-). So in what syntax would I use -pi?

--perl.j


Comment on Re^2: s// All Files In Directory
Re^3: s// All Files In Directory
by aaron_baugher (Deacon) on Apr 02, 2012 at 20:00 UTC

    Learn to be good with the command line. Being saddled with Windows is no excuse; if you can't stand the Windows command line (I can't), install Cygwin.

    -p process line-by-line and print the results -i operate on files in place -e execute the following code Hence: perl -p -i -e 's/foo/bar/g' *

    Aaron B.
    My Woefully Neglected Blog, where I occasionally mention Perl.

      So perl -p -i -e 's/5/6/g' will do what I want?
      --perl.j

        No. You have to add the file names you want to work with after the command. In your case you want to work with all files, so append an asterisk (*). Also, add a file extension to 'i' if you want to create a backup:

        perl -pi.bak -e 's/5/6/g;' *

        ...will create a copy of each file with a .bak extension before performing the search/replace. If you only want to affect certain files, name them explicitly, or use glob patterns. For instance, the following will only work on files with a .txt extension:

        perl -pi -e 's/5/6/g;' *.txt

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://963102]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2014-12-26 01:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (163 votes), past polls