Help with command list batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
hateful
Posts: 4
Joined: 12 Jun 2010 11:23

Help with command list batch

#1 Post by hateful » 12 Jun 2010 11:31

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.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Help with command list batch

#2 Post by aGerman » 12 Jun 2010 14:03

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

hateful
Posts: 4
Joined: 12 Jun 2010 11:23

Re: Help with command list batch

#3 Post by hateful » 13 Jun 2010 05:17

Indeed it worked like you posted.

But what was wrong with the other way? Why was it only processing one file?

Thank you!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Help with command list batch

#4 Post by aGerman » 13 Jun 2010 05:43

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"

hateful
Posts: 4
Joined: 12 Jun 2010 11:23

Re: Help with command list batch

#5 Post by hateful » 13 Jun 2010 06:56

Yes I thought about that and tried it, but same result!

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

Re: Help with command list batch

#6 Post by avery_larry » 15 Jun 2010 15:01

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.

hateful
Posts: 4
Joined: 12 Jun 2010 11:23

Re: Help with command list batch

#7 Post by hateful » 15 Jun 2010 15:26

Ah I see!

Thank you!

Post Reply