Anonymous user
Globally replace text in several files: Difference between revisions
m
→version 1: used zero-based indexing (to make program simplier).
m (→version 1: added/changed comments, indentations, and whitespace.) |
m (→version 1: used zero-based indexing (to make program simplier).) |
||
Line 989:
===version 1===
This example works under "DOS" and/or "DOS" under Microsoft Windows.
<br><br>
<lang rexx>/*REXX program reads the files specified and globally replaces a string. */
old= "Goodbye London!" /*the old text to be replaced. */
Line 1,000:
call linein fn,1,0 /*position the file for input. */
changes=0 /*the number of changes in file so far.*/
do rec=
@.rec=linein(fn) /*read a record (line) from the file. */
if pos(old, @.rec)==0 then iterate /*Anything to change? No, then skip. */
Line 1,006:
@.rec=changestr(old, @.rec, new) /*change the @.rec record, old ──► new.*/
end /*rec*/
say '──────── file has been read: ' fn", with " rec 'records.'
if changes==0 then do; say '──────── file not changed: ' fn; iterate; end
Line 1,012:
say '──────── file being changed: ' fn
do r=
end /*r*/
|