Anonymous user
Globally replace text in several files: Difference between revisions
Globally replace text in several files (view source)
Revision as of 21:18, 16 January 2013
, 11 years ago→Version 1: changed comments and indentation, added whitespace, simplified the program, made the (hdr) eyecatcher better. -- ~~~~
(Added Vedit macro language) |
m (→Version 1: changed comments and indentation, added whitespace, simplified the program, made the (hdr) eyecatcher better. -- ~~~~) |
||
Line 649:
=={{header|REXX}}==
===
This example works under "DOS" and/or "DOS" under Microsoft Windows.
<lang rexx>/*REXX program to read the files specified and globally replace a string*/
old = 'Goodbye London!' /*old text to be replaced. */
new = 'Hello New York!' /*new text used for replacement. */
parse arg fileList; files=words(fileList); pad=left('',20)
hdr='────── file' /*eyecatcher.*/
do f=1 for files;
say hdr'
call linein aFile,1,0 /*position the file for input. */
changes=0 /*
say '... file was being read: ' aFile", with " recs 'records.'▼
if changes==0 then do▼
say '... file not changed: ' aFile▼
iterate /*f*/▼
end▼
▲ if changes == 0 then do
call lineout aFile,,1 /*position the file for output. */
say hdr '
▲ call lineout aFile,@.r /*write this record to output. */
▲ say '... file was changed: ' aFile " with" changes 'lines changed.'
end /*f*/
/*stick a fork in it, we're done.*/</lang>
Line 715 ⟶ 708:
'''output''' when using the input of: <tt> one.txt two.txt </tt>
<pre style="overflow:scroll">
────── file was changed: one.txt with 2 lines changed.
</pre>
|