Page 1 of 1
Help with command list batch
Posted: 12 Jun 2010 11:31
by hateful
Hello I'm trying to make a batch file run a serie of commands to do a string replacement on several txt files. I'm also using a batch file which I got from this site (thank you btw).
Here's what I'm trying to do:
Code: Select all
BatchSubstitute.bat "." "," "FTIR.txt"
BatchSubstitute.bat "." "," "NSTEP10.txt"
BatchSubstitute.bat "." "," "NSTEP20.txt"
BatchSubstitute.bat "." "," "NSTEP40.txt"
But when I run it, only the first file (and thus the first line on the batch) gets processed.
Can you please tell me what I'm doing run and explain it?
Thank you in advance.
Re: Help with command list batch
Posted: 12 Jun 2010 14:03
by aGerman
All in one batch, you could try this:
Code: Select all
@echo off &setlocal
set "tmpFile=%temp%\tmp.txt"
call :substitute "FTIR.txt"
call :substitute "NSTEP10.txt"
call :substitute "NSTEP20.txt"
call :substitute "NSTEP40.txt"
del "%tmpFile%"
goto :eof
:substitute
move "%~1" "%tmpFile%"
for /f "delims=: tokens=1*" %%a in ('findstr /n "^" "%tmpFile%"') do (
set "line=%%b"
if not defined line (
>>"%~1" echo.
) else (
>>"%~1" call echo %%line:.=,%%
)
)
goto :eof
Regards
aGerman
Re: Help with command list batch
Posted: 13 Jun 2010 05:17
by hateful
Indeed it worked like you posted.
But what was wrong with the other way? Why was it only processing one file?
Thank you!
Re: Help with command list batch
Posted: 13 Jun 2010 05:43
by aGerman
I'm not that sure, because I never used this batch tool. But certainly you would need two files for each command line (one for reading and one for writing).
Maybe this would work:
BatchSubstitute.bat "." "," "FTIR.txt">"New_FTIR.txt"
Re: Help with command list batch
Posted: 13 Jun 2010 06:56
by hateful
Yes I thought about that and tried it, but same result!
Re: Help with command list batch
Posted: 15 Jun 2010 15:01
by avery_larry
call batchsubstitute ...
call batchsubstitute ...
if you don't use the "call" statement, then you pass control to the other batch file and you do not return to the calling batch file.
Re: Help with command list batch
Posted: 15 Jun 2010 15:26
by hateful
Ah I see!
Thank you!