Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Replacing text inside lots of files

by hanenkamp (Pilgrim)
on Oct 28, 2003 at 14:09 UTC ( [id://302688]=note: print w/replies, xml ) Need Help??


in reply to Replacing text inside lots of files

Well for text replacement, the obvious solution is regular expressions. You should see perlrequick, perlretut, and perlre for starters. Just as an example, if your first line contains the text REPLACEME, you could do something like:

use English; # for $INPUT_LINE_NUMBER instead of $. # open files FILE and OUT while (<FILE>) { s/REPLACEME/$filename/ if $INPUT_LINE_NUMBER == 1; print OUT $_; } # close files

You may also want to see English and perlvar for details on $. and the $INPUT_LINE_NUMBER variables (and cousins that I haven't mentioned).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-03-29 06:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found