Skip to main content
added 2 characters in body
Source Link
user51827
user51827

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.nbtxt and epithets.nbtxt, 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.nbtxt and another from epithets.nbtxt (for example, let's say in one case it chooses an element randomly and in the other it chooses the nth where n = 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.)

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.nb and epithets.nb, 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.nb and another from epithets.nb (for example, let's say in one case it chooses an element randomly and in the other it chooses the nth where n = 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.)

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 from epithets.txt (for example, let's say in one case it chooses an element randomly and in the other it chooses the nth where n = 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.)

edited tags
Link
Source Link
user51827
user51827

How can I input this simple text file, process it, and export to another text file?

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.nb and epithets.nb, 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.nb and another from epithets.nb (for example, let's say in one case it chooses an element randomly and in the other it chooses the nth where n = 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.)