Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have 3 text files, each containing one item of data per row. viz
1.txt
---------
1
2
3
2.txt
----------
a
b
c
3.txt
----------
alpha
beta
gamma
The data in the text files is such that data on line 1 in text file 1 is directly related to data on line 1 in file 2 and data on line 1 in text file 3 and so on.I need to loop through each text file in such a way that I can output each line from each file as arguments to another script:
Script.cmd 1 a alpha
Script.cmd 2 b beta
Script.cmd 3 c gammaBut I cant get it to work..
Can anyone help?
Cheers all
Alastair

@echo off & setlocal EnableDelayedExpansion > out.tmp set cnt=0& for /F %%j in (1.txt) do call :NORM A %%j set cnt=0& for /F %%j in (2.txt) do call :NORM B %%j set cnt=0& for /F %%j in (3.txt) do call :NORM C %%j set tail= set cnt=0 for /F "tokens=2 delims=~" %%j in ('sort ^< out.tmp') do ( set /A cnt+=1 set tail=!tail! %%j if !cnt! equ 3 ( script.cmd !tail! set tail= set cnt=0 ) ) del out.tmp goto :EOF :NORM set fcnt=%cnt% if %cnt% lss 10 set fcnt=0%fcnt% if %cnt% lss 100 set fcnt=0%fcnt% if %cnt% lss 1000 set fcnt=0%fcnt% echo.%1%fcnt%~%2>> out.tmp set /A cnt+=1 goto :EOF

im going to need to spend some time getting my head around that one tomorrow..
thanks for your reply.

Sorry there is a bug in the script, replace
echo.%1%fcnt%~%2>> out.tmp with echo.%fcnt%%1~%2>> out.tmp
that is the third line from the bottom.The script is modular and quite simple in its structure. If you need more support contact me by a private message.

There is another issue in the script posted to be mentioned.
The way to run the script.cmd may vary according to the kind of the script itself, i.e.
.bat or .cmd call script !tail! .exe (program) prog !tail!
not sure in the case of a vbscript, probably like calling an executable, i.e. "vbscript !tail!"..cmd is interpreted as .bat and is a legacy suffix used under OS/2 systems.

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |