You have a line of code that works.
Some part of that code is changing over short period of time.
There are different ways of getting what you want.
I tried to explain it in most basic way as a starting point.
In the end I do it all with script in more effective way but in this case BBC is not worth pulling my middle leg.
You ask should it be written as that in CMD?
It is up to you if you like it one way or another.
You write code how it is best readable and understandable to you.
If that code confuses you than you need to learn more about scripting to understand it.
Fetch text should not to be saved as file with working code.
Once in memory, process the data in memory. That way is less work and quicker way.
How would I show you what data am I talking about if I don't show you as text and you see it as text?
To understand it more is to learn more and it is the hardest thing to weed out what to learn and from where.
Your specific question is about CMD scripting.
Most of times you need some other programming language to do more with less pain.
https://www.robvanderwoude.com/batchstart.php