Reverse prior batch job (without simply rewriting the script)

So, let's say I have a usual batch rename file like this:

and I'd like to have a secon bat file, that can /reverse" the first.

BUT, I don't want to simply "rewrite" it like

move hello 254352426

but rather, have the new script take the source and destination and reverse it somehow like this:

move "var1" "var2"

Is this possible ?

  • pasc

It may be not that simple, to reverse a script.

For example, if you have a file consisting of a and b characters. Your normal script replaces a with b. How do you reverse that? It's not possible to know original a's had been.

That maybe possible or impossible depending on the specific task. But there's hardly a generic way to do this.

If the task is about manipulating files you may take a backup before the task via cp, tar, rsync, ... and reset the state to that backup when needed.

What are you about to do? Why do want to reverse an action? What exactly do you want to reverse?

And of course: What's your OS environment and programming language/shell?

What are you about to do? Why do want to reverse an action?

Simple:

I want to have a second script that is not simply a "line by line reverse copy" of the first script,
but rather something that reads from the first.
=> So I don't have to have update two scripts.

Example:

TL;DR:
I want to have a script that parses another script and does the job in another order.

I want to have a script that parses another script and does the job in another order.

I would not say this isn't possible, but extremely complex to parse any scripting language or shell. I wouldn't ever dare to start such a program even having 20+ years of experience in scripting.

You need to have the skill level of a compiler/interpreter developer. Definitively not a practical way to go.

An option i got to know of are snaphotting tools: Run some programm. Look what it did(changed files, permissions,...) and undo the effects made.

Besides: We're at unix.com here. I doubt that you find much ms windows expertise here.

It may be as simple as

awk '{print $1, $3, $2}' file

and pipe the result into sh . Be aware that when "automating" things you should know exactly what you are doing , and do a test run before each "live" run...

Thats what I sadly figured, but asking is free of charge as they say :wink:

That looks interesting, sadly I'd have to run this via windows utitlites (awk might exist, but it isn't stock inventory).

The good news for my script is that the

"move" "parameter 1" "parameter2"

are certainly constant. Also they are all seperated by one " " space and each line is build that way.

If it was possible to move -one line at a time- and use these parameters" that way.. hmm..

If your original scripts are that simple, I would be surprised if there's no possibility to do it.

Those techs (stock windows) will probably enable you to script a solution:

Visual Basic Script
Powershell
Windows Script Host