Reputation: 389
I have a textfile (.txt), that is built like this:
;ARPE for Ariminum
event plague ARPE_RIDaba
date RND summer
position 96, 81
;ARPE for Tara
event plague ARPE_RIDbbg
date RND summer
position 34, 143
Now I need a batch script, which will replace all the "RND" in my file with a random number between 1 and 250 (no comma, only whole numbers). But I do not want every RND to become the same. I want each RND to be assigned random and independent from the others. Also, the text file is coded in UTF-8 without BOM and it must stay like this.
Is there any solution for that?
Upvotes: 0
Views: 60
Reputation: 130889
You could use my JREPL.BAT regular expression text processing utility - pure script (hybrid JScript/batch) that runs natively on any Windows machine from XP onward.
call jrepl "\bRND\b" "Math.round(Math.random()*250)+1" /j /f test.txt /o -
The above will write all lines with \r\n line terminators, regardless what form the original had. If you want to preserve the original line terminators, then you can add the /M multi-line option:
call jrepl "\bRND\b" "Math.round(Math.random()*250)+1" /m /j /f test.txt /o -
Upvotes: 1