Globally replace text in several files: Difference between revisions
Content added Content deleted
m (→version 1: elided a blank line.) |
|||
Line 854: | Line 854: | ||
<lang perl6>slurp($_).subst('Goodbye London!', 'Hello New York!', :g) ==> spurt($_) |
<lang perl6>slurp($_).subst('Goodbye London!', 'Hello New York!', :g) ==> spurt($_) |
||
for <a.txt b.txt c.txt>;</lang> |
for <a.txt b.txt c.txt>;</lang> |
||
=={{header|Phix}}== |
|||
ctrace.out was just a file that happened to be handy, obviously you'd have to provide your own file list.<br> |
|||
as hinted, you could probably improve on the error handling. |
|||
<lang Phix>procedure global_replace(string s, string r, sequence file_list) |
|||
for i=1 to length(file_list) do |
|||
string filename = file_list[i] |
|||
integer fn = open(filename,"rb") |
|||
if fn=-1 then ?9/0 end if -- message/retry? |
|||
string text = get_text(fn) |
|||
close(fn) |
|||
text = substitute(text,s,r) |
|||
fn = open(filename,"wb") |
|||
puts(fn,text) |
|||
close(fn) |
|||
end for |
|||
end procedure |
|||
sequence file_list = {"ctrace.out"} |
|||
global_replace("Goodbye London!", "Hello New York!", file_list)</lang> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |