Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Had a boss show me this one once and it really opened my eyes up. I just never paid attention to those "other" switches you could add to the shebang. What he showed me is a way to combine a two line perl script to a find to change every single file in a directory structure at once (The actual scenario was we had a client lose their hostname through shear incompetence and we had to compensate with what they could get from internic - and we needed to change every file in their web site simultatneously because they also had a practice of hardocding URL's into their site - if it isn't complex, it isn't life...).

OK, here's the code, followed by the explanation...

#!/usr/bin/perl -pi $_ =~ s/sometext/someothertext/mg;

Yeah, that's the whole script. The secret is in the -pi. Check out the perldoc perl pages for more information - this form replaces the page entriley. You can also set it so perl writes a backup file as it goes too. To use the script, just do a find exec, like so:

find ./ -name "*" -type f -exec ./ {} \;

Believe me, this has been a lifesaver. Like moving netscape server instances between servers so you don't have to retweak....

Zed? Zed's dead, baby, Zed's dead.

In reply to Need to change, oh, every file at once? by z3d

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2023-06-09 11:50 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (35 votes). Check out past polls.