Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I'm looking to write a batch file to get information from one text file and create multiple text files based on say a batch number, I've added below a sample of the original text file, oh yes I need all the info related to that particular batch number included also ( there maybe multiple mixes related to a batch number ) I hope I have been clear if not please let me know.
**below is the file**Production Batch: 10
Mix 1 of 1Ingredient Setpoint Actual
Silo 4 0.00 0.00
Silo 1 1500.00 1508.70
Mix Status: Completed
_________________________________________________________________________________________
Production Batch: 10
Mix 1 of 1Ingredient Setpoint Actual
Silo 4 0.00 0.00
Silo 1 1500.00 1505.90Mix Status: Completed
_________________________________________________________________________________________Production Batch: 11
Mix 1 of 1Ingredient Setpoint Actual
Silo 4 0.00 0.00
Silo 1 1500.00 1506.60Mix Status: Completed
__________________________

Hi
You mean collect all records with the same Batch number into there own seperate files.I'm not familar with NT but I using WinXP Pro
which is very similar I belive.are these commands allowed in NT
nested if allowed with else
if 45==45 (
do somthing
) else
do somthing
)set /a 3+4
set xx=%Date;~0,3%
I have all ready written the batch file in
XP, but if might have to be modified if possable to work with NT.

MickD,
Check your mail box, I have sent you the script you need based on the specs you posted.
Dtech10,
The scripts for Win XP work under 2K and NT too.
There are two families of Windows systems, the NT-kernel (NT/2K/XP) and the DOS-kernel based (95/98/ME). From the point of view of batch scripting each product belonging to a family is invariant.
I do not post the script as it is quite complex and posting may lead to misunderstanding the exact format of statements.

Hi MickD
This works ok with WinXP.rem Main.bat
@echo off
if exist *.tx_ del *.tx_
for /f "tokens=*" %%A in (Data.txt) do call MakeFiles.bat %%A
---rem MakeFiles.bat
@echo off
set Data=%*
if "%Data:~0,17%"=="Production Batch:" (
set Count=1
set Mix=%Data:~18,2%.tx_
) else (
set /a Count=%Count%+1
)
if %Count% lss 7 (
echo %* >> %Mix%
if %Count%==6 echo. >> %Mix%
)

thanks guys for the quick responses, the file Ivo sent works exactly as I needed it to thanks very much for this Ivo, dtech10 thanks for your suggestions also, I'm new to batch scripting so I'm sure I'll need your help in the near future.
thanks again guys.
MickD

MickD,
Sorry, but I can't point you to a valuable Web site to learn about batch sacripting. My know-how is the result of a long practical experience starting from the DOS age.
There is really a lack on this resource, in books and Websites, the best thing, however not friendly, is to walk through the (in)famous on-line help using the /? switch even on supposed known commands: surprises stem out!
A good site to catch some tips is
http://Batch.hpg.com.br from Secret_Doom
Keep always well in your mind there are two quite different strains of scripts: for NT and for DOS, and there is no full compatibility across them.
Dtech10,
My script is very similar to what you posted, may I give you a tip?
Instead of splitting your code into two batches, use the powerfull internal Call statement:
Call :MAKE %%A
where :MAKE (or what you like) is an internal label starting a routine to be ended with :EOF (the : are mandatory).
In that way the code is more compact and cleaner. See Call /? to know more.

Sorry, errata
a routine to be ended with :EOF
corrige
a routine to be ended with GoTo :EOF
So
Rem Main Body
Call :MAKE [parameters]
---------
--------
--------
GoTo :EOF [Return to Windows]Rem MAKE subroutine
:MAKE
-------
-------
-------
GoTo :EOF [Return to Main]

Hi IVO
Thanks again for the tip. I've just started learning batch script files.
I have used them before but a long time ago. NT/2000/XP has make a lot more usefull additions which I've ever used before.Thanks DTech

A question - How is the data stored if you have the same batch number, you can't have 2 files with the same batch number?
and a comment - It seems that separating the data is making more work. Wouldn't sending the data to one file (a database) make it easier to use the data, each record would contain a batch.

wizard-fred,
what MickD needed is a splitting routine that extracts each numbered batch collecting all same numbered slices into one file, so
BT_10.txt collects all Batch: 10 headed lines and so on.
I agree there are smarter solutions to process that kind of data, but here we deal with simple information filtering using basic built-in functions of the operating system only.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |