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*/ |
||
#= words(fileList) /*the number of files in the file list.*/ |
|||
do f=1 for |
do f=1 for #; fn= translate( word(fileList, f), , ','); say; say |
||
say '──────── file is being read: ' fn " ("f 'out of' |
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= |
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) |
@.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 |
changes= changes + 1 /*flag that file contents have changed.*/ |
||
@.rec=changestr(old, @.rec, 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> |
||
{{out|output|text= when using the input (list of files) of: <tt> one.txt 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). |