Task

Replace every occurring instance of a piece of text in a group of text files with another one.



For this task we want to replace the text   "Goodbye London!"   with   "Hello New York!"   for a list of files.




without js -- file i/o
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)
