I think it depends on where most of the file processing and decision making is being done and on the scripting facilities available to you outside of Vim. Since most of the processing you're doing seems to be running a sequence of programs, perhaps in a pipeline, I'd be inclined to put all that into a shell script or a batch file and launch that from Vim. (You wrote that you use sed. Do you have access to a Unix shell as well?) If you don't have access to a Unix shell and you find yourself limited by the batch file command set, then you could put all the commands into a Vim function. Putting the commands into a Vim function gives you a little more flexibility and easier programming than trying to quote everything just right for a Vim command or mapping.
You can put shell commands inside functions pretty easily like this
call system('echo "hello"')
as well as
for more on this. For more on commands and mappings, see
You can write a command to call your function like this:
:command Foo call Foo()
so that you can execute your function with