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.




fcn sed(data,src,dst){
   srcSz:=src.len(); dstSz:=dst.len(); md5:=Utils.MD5.calc(data);
   n:=0; while(Void!=(n:=data.find(src,n)))
           { data.del(n,srcSz); data.insert(n,dst); n+= dstSz; }
   return(md5!=Utils.MD5.calc(data)); // changed?
}
fcn sedFile(fname,src,dst){
   f:=File(fname,"r"); data:=f.read(); f.close();
   if(sed(data,"Goodbye London!", "Hello New York!"))
      { f:=File(fname,"w"); f.write(data); f.close(); }
}