Computing.Net > Forums > Programming > Batchfile Help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batchfile Help

Reply to Message Icon

Name: MickD
Date: February 26, 2004 at 04:21:01 Pacific
OS: windows NT
CPU/Ram: P3 800 128MB
Comment:

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 1

Ingredient Setpoint Actual
Silo 4 0.00 0.00
Silo 1 1500.00 1508.70

Mix Status: Completed
_________________________________________________________________________________________


Production Batch: 10
Mix 1 of 1

Ingredient Setpoint Actual
Silo 4 0.00 0.00
Silo 1 1500.00 1505.90

Mix Status: Completed
_________________________________________________________________________________________

Production Batch: 11
Mix 1 of 1

Ingredient Setpoint Actual
Silo 4 0.00 0.00
Silo 1 1500.00 1506.60

Mix Status: Completed
__________________________




Sponsored Link
Ads by Google

Response Number 1
Name: MickD
Date: February 26, 2004 at 04:25:51 Pacific
Reply:

forgot to mention i would like to name the newly created files as the batch number.
Thanks

MickD


0

Response Number 2
Name: dtech10
Date: February 26, 2004 at 08:40:25 Pacific
Reply:

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.


0

Response Number 3
Name: IVO
Date: February 26, 2004 at 14:18:55 Pacific
Reply:

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.


0

Response Number 4
Name: dtech10
Date: February 26, 2004 at 15:10:31 Pacific
Reply:

Hi IVO
Thanks for the info.
I was'nt sure of this since I have only used WinXP Pro.


0

Response Number 5
Name: dtech10
Date: February 26, 2004 at 15:15:28 Pacific
Reply:

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%
)


0

Related Posts

See More



Response Number 6
Name: MickD
Date: February 27, 2004 at 01:52:50 Pacific
Reply:

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


0

Response Number 7
Name: IVO
Date: February 27, 2004 at 02:41:48 Pacific
Reply:

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.


0

Response Number 8
Name: IVO
Date: February 27, 2004 at 02:50:39 Pacific
Reply:

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]


0

Response Number 9
Name: dtech10
Date: February 27, 2004 at 06:56:25 Pacific
Reply:

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


0

Response Number 10
Name: wizard-fred
Date: February 27, 2004 at 07:33:11 Pacific
Reply:

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.


0

Response Number 11
Name: IVO
Date: February 27, 2004 at 07:47:54 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batchfile Help

batchfile help www.computing.net/answers/programming/batchfile-help/19142.html

Help fix PING batch file www.computing.net/answers/programming/help-fix-ping-batch-file/19510.html

Batch: Help www.computing.net/answers/programming/batch-help/19864.html