Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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 surveying the Monastery: (5)
As of 2025-01-13 10:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (28 votes). Check out past polls.