Wondering if anyone has a batch file that will work with a trail file segment and a list of files to build a long trail file.
I have the following files:
In the new file I want:
Essentially a for each command with text replacement and append the new file with the modified trail-2.txt each time.
Solved! Go to Solution.
Ok, I see your problems and how the last two for /f statements didn't work.
Try this version:
for /F "tokens=2 skip=1 delims= " %%A IN (mass-parameter-update.idx) DO @echo %%A >> instance-list.txt
call remove-last-line.cmd instance-list.txt
for /F "tokens=3 skip=1 delims= " %%A IN (mass-parameter-update.idx) DO (set generic_name=%%A)
copy trail-1.txt big-trail-test.txt
echo Ready to start the substitution - replacing GENERIC-PART...
call batchsubstitute.bat GENERIC-PART %generic_name% trail-2.txt >> trail-3.txt
echo Ready to start the substitution - replacing FAMILY-INSTANCEs...
for /F "tokens=1" %%A IN (instance-list.txt) DO (call batchsubstitute.bat FAMILY-INSTANCE %%A trail-3.txt >> big-trail-test.txt)
I also shortened up some of the code that extracts the name of the generic from the .idx file.
And removed the first of the problematic for /f statements - no need for it as you are calling batchsubstitute.bat just once.
But the key problem was that you were missing the CALL keyword - see line 8.
Not sure that's really what I was after. I need a function to replace a string in one of the trail files because I'm opening instances of a family table and doing something to each one then backing it up. I don't want to have to pick the instance manually when running the trail file. We could have hundreds or thousands of instances.
Attached is Edwin Muirhead's original Trail Maker.htm, which in reality is just a java script. You can view it in notepad++. I've use this in the past, but it's not working for what I need to do now. Not sure why, I think there's too much hard coded in it to work with the current rev of Creo.
Also attached are my sample files and the resulting file I made manually to test the function of the longer trail file. The file list came from idx file when I backed up the generic to the folder. I just opened it in notepad++ and use alt select to select a box with just the instance names and saved that as file-list.txt
Essentially I think this can all be done in perl, or even a cmd file. The simpler the better.
The core of the script would do the following:
Ideally the script would have a set command at the top where you could specify the string to search for and replace.
To me the more basic this script is, all text based the better, then it's uber flexible to be modified to any use I want.
I'm sure I could figure this out if I had the time, but right now I don't have the time, and I was hoping someone had done something like this in the past.
I used autohotkey for this task in the past, because of the clipboard functionality. But i'm sure it is easy to convert to work with files. In the top is the header, in the left text field the trail content and in the right text field you can put the list of files. File list can also be in clipboard. But you need autohotkey (opensource tool) to run or compile it to an executable.
you can test my gizmo.
I haven't had a chance to test the other two ideas from Andreas or Martin yet. I was playing with this today. I have commands that work, but they bomb out when I combine them into a full script.
Work flow I'm trying to achieve.
I cobbled together some stuff from the internet today and have the concept working from the command line.
Now I know I need to have call in front of some of these commands in a script and I have to double up the %'s in the for statements.
Eventually I should add a command to figure out what the name of the folder is.
My problem is it's failing on the last two for /f commands when combined into one.
I tried breaking them out into separate scripts and then calling them from a master script that continues to fail on the last two for commands.
The thing is, each script works on it's own. They are attached.
The problem, I'm sure, all has to do with the syntax in the for /f command, but I'm unsure how to fix it.
I'm sure this could all be cleaned up with something slicker. But I want to keep it flexible enough so it can be reused on other projects with different trial files. And I want to avoid complied programs. My preference is to stick with native windows scripting.
I didn't look through your scripts but I do want to help so I attached my batch file that:
This script is just part of our all-in-one release mapkey.
Please let me know if this is of any help.
At least you should find some working (in Windows 7) "for" commands.
I've looked at your script files, but frankly I'm confused about your statement about "My problem is it's failing on the last two for /f commands when combined into one", because I don't know where that is, or for that matter, what is failing. Is the file cmd-commands.txt in an editor and you are copying and pasting its lines into a separate command window?
I'd like to help, but I need to have these:
sample of the input files: trail-1.txt, mass-parameter-update.idx
the "desired" intermediate files: instance-list.txt, generic.txt, trail-2.txt, trail-3.txt
the "desired" output file: Modify-family-table.txt (or is it big-trail-test.txt?)