I will try to keep this example very specific and simple. Let us say I have a text file called file.txt
, with path C:/Ruffle/bunch-of-files/file.txt
, and with content as follows:
Hello, XXX, you YYY!
And I have also got two files containing ordered lists, namely names.txt
and epithets.txt
, both in directory C:/Ruffle/bunch-of-lists/
and with content as follows:
{John, Mary, Algernon}
{Honey Biscuit, Old Twit, Wonderful Person}
What do I need to put in a short Mathematica notebook that
- imports
file.txt
- applies specified rules to choose an element from
names.txt
and another fromepithets.txt
(for example, let's say in one case it chooses an element randomly and in the other it chooses the nth wheren = 1 + Mod[DateList[][[3]], 3]
) - substitutes them for "XXX" and "YYY" respectively
- saves the result as
C:/Ruffle/bunch-of-amended-files/amended-file.txt
- closes
file.txt
?
(The reason I have assigned this question an HTML
tag as well as a text
one is that what I need is to output HTML files. So amended-file.txt
would actually be amended-file.html
, and the Mathematica notebook would also have to insert a specified header and tags. But since an HTML file is only a text file, the problem is one of text processing, and I am trying to keep the question as simple as possible.)