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.




procedure main()
globalrepl("Goodbye London","Hello New York","a.txt","b.txt") # variable args for files
end
 
procedure globalrepl(old,new,files[])  
 
every fn := !files do 
   if s := reads(f := open(fn,"bu"),stat(f).size) then {
      writes(seek(f,1),replace(s,old,new))
      close(f)
      }
   else write(&errout,"Unable to open ",fn)
end
 
link strings # for replace