Globally replace text in several files: Difference between revisions

m
→‎version 1: added whitespace, used a template for the output section.
m (newLISP: fixed "works with")
m (→‎version 1: added whitespace, used a template for the output section.)
Line 1,181:
new= "Hello New York!" /* " new " used for replacement. */
parse arg fileList /*obtain required list of files from CL*/
files#= words(fileList) /*the number of files in the file list.*/
 
do f=1 for files#; fn= translate( word(fileList, f), , ','); say; say
say '──────── file is being read: ' fn " ("f 'out of' files # "files)."
call linein fn,1,0 /*position the file for input. */
changes=0 0 /*the number of changes in file so far.*/
do rec=0 while lines(fn)\==0 /*read a file (if it exists). */
@.rec= linein(fn) /*read a record (line) from the file. */
if pos(old, @.rec)==0 then iterate /*Anything to change? No, then skip. */
changes= changes + 1 /*flag that file contents have changed.*/
@.rec= changestr(old, @.rec, new) /*change the @.rec record, old ──► new.*/
end /*rec*/
 
Line 1,206:
Some older REXXes don't have a   '''changestr'''   BIF,   so one is included here   ──►   [[CHANGESTR.REX]].
<br><br>
'''{{out|output''' |text=&nbsp; when using the input (list of files) of: &nbsp; &nbsp; <tt> one.txt &nbsp; two.txt </tt>}}
<pre>
──────── file is being read: one.txt (1 out of 2 files).