Globally replace text in several files: Difference between revisions

Content added Content deleted
m (newLISP: fixed "works with")
m (→‎version 1: added whitespace, used a template for the output section.)
Line 1,181: Line 1,181:
new= "Hello New York!" /* " new " used for replacement. */
new= "Hello New York!" /* " new " used for replacement. */
parse arg fileList /*obtain required list of files from CL*/
parse arg fileList /*obtain required list of files from CL*/
files=words(fileList) /*the number of files in the file list.*/
#= words(fileList) /*the number of files in the file list.*/


do f=1 for files; fn=translate(word(fileList,f),,','); say; say
do f=1 for #; fn= translate( word(fileList, f), , ','); say; say
say '──────── file is being read: ' fn " ("f 'out of' files "files)."
say '──────── file is being read: ' fn " ("f 'out of' # "files)."
call linein fn,1,0 /*position the file for input. */
call linein fn,1,0 /*position the file for input. */
changes=0 /*the number of changes in file so far.*/
changes= 0 /*the number of changes in file so far.*/
do rec=0 while lines(fn)\==0 /*read a file (if it exists). */
do rec=0 while lines(fn)\==0 /*read a file (if it exists). */
@.rec=linein(fn) /*read a record (line) from the file. */
@.rec= linein(fn) /*read a record (line) from the file. */
if pos(old, @.rec)==0 then iterate /*Anything to change? No, then skip. */
if pos(old, @.rec)==0 then iterate /*Anything to change? No, then skip. */
changes=changes + 1 /*flag that file contents have changed.*/
changes= changes + 1 /*flag that file contents have changed.*/
@.rec=changestr(old, @.rec, new) /*change the @.rec record, old ──► new.*/
@.rec= changestr(old, @.rec, new) /*change the @.rec record, old ──► new.*/
end /*rec*/
end /*rec*/


Line 1,206: Line 1,206:
Some older REXXes don't have a   '''changestr'''   BIF,   so one is included here   ──►   [[CHANGESTR.REX]].
Some older REXXes don't have a   '''changestr'''   BIF,   so one is included here   ──►   [[CHANGESTR.REX]].
<br><br>
<br><br>
'''output''' &nbsp; when using the input (list of files) of: &nbsp; <tt> one.txt &nbsp; two.txt </tt>
{{out|output|text=&nbsp; when using the input (list of files) of: &nbsp; &nbsp; <tt> one.txt &nbsp; two.txt </tt>}}
<pre>
<pre>
──────── file is being read: one.txt (1 out of 2 files).
──────── file is being read: one.txt (1 out of 2 files).