Creating Text files using Batch (Or anything) in an order / pattern

1

I need to create a file to finish a mod i am working on, except it would take way too long to do it manually.

Cutting to the chase i need to create a file that looks like the following

1|5.000
2|4.950
3|4.900
4|4.850

And that pattern to be repeated X times or until the second number is 0.5 for example, the number before the " | " is not important, it's only for organization and / or naming, I can probably add it in post, I did this on a smaller scale manually of ~30 numbers and it was tedious enough, but i got to a point where i actually need this on a far larger scale.

I've yet to find a way to automate that kind of a process with "online text tools" and have been trying to figure out how to do patterns like that for a while, though it's a bit difficult to Google it (Or at least for me, I'm not a native English speaker)

What would be the best way to approach this?

Thanks in advance guys!

Martin Angelov

Posted 2017-07-29T22:32:02.137

Reputation: 13

Use a bash/awk/perl script, or any language you are comfortable with. Otherwise use Excel and export to text file. – simlev – 2017-07-29T22:51:09.560

1Ah, How did i not think of excel!! In fact even Google Sheets worked, just had to export as tab separated values format and open with Notepad++ and worked perfectly, Thank you so much! – Martin Angelov – 2017-07-29T22:57:51.743

Answers

0

Here's a solution in perl:

perl -e 'for ($i=1;$i<=90;$i++){printf("%s|%.3f\n", $i,5-.05*$i);}'>out.txt

You could use any programming language you might be comfortable with. In case there are none, you can accomplish the same with a spreadsheet (Excel, Gnumeric, Libreoffice Calc, Google Sheets...) and then export as a text file.

simlev

Posted 2017-07-29T22:32:02.137

Reputation: 3 184

0

Install CudaText editor. Free, cross-platform.

Call menu item "Plugins / Make plugin". Enter defaults, menuitem name "My". New py file is created. Enter such body:

from cudatext import *
from decimal import Decimal

class Command:
    def run(self):

        v0 = Decimal('5.000')
        vend = Decimal('4.500')
        i = 0
        res = []
        while v0>vend:
            v0 -= Decimal('0.050')
            i += 1
            res += [str(i)+'|'+str(v0)]

        file_open('')
        ed.set_text_all('\n'.join(res))
  • Restart CudaText
  • Call menu item "Plugins / My"
  • Output is created in a new file tab.

Cud2

Posted 2017-07-29T22:32:02.137

Reputation: 1