tags:

views:

162

answers:

6
Q: 

Batch File

Hi All

I have a batch file that does this.

ECHO A41,35,0,a,1,1,N,"Mr ZACHARY KAPLAN">> test.txt

There are about 30k similar lines. It takes the batch file about 5 hours to run.

Is there a way to speed this up?

/Jeanre

+1  A: 

Write a custom script or program to open the file test.txt once, and write all the data into it in one shot.

Right now each line is executed separately by the command interpreter, and the file is opened and closed each time.

Even a small qbasic program should be able to strip out the data between the echo and >> and write it to a text file more quickly than your current method.

Adam Davis
A: 

Here's an example using a Java program - with BufferedReader/PrintWriter

http://www.javafaq.nu/java-example-code-126.html

You can also use a BufferedReader and BufferedWriter

http://java.sun.com/docs/books/tutorial/essential/io/buffers.html

http://leepoint.net/notes-java/io/10file/10readfile.html

Kelvin Meeks
A: 

The thing is the batch file comes from a web application, what I was thinking was

doing echo "text" \n "text" so it does not open / save the file after each line.

But there is no newline in batch? :(

"echo ." will do a newline
schnaader
A: 

you can use a scripting language to strip the leading ECHO and trailing >> test.txt with a small regular expression

here's an example in python:

>>> import re
>>> text = 'ECHO A41,35,0,a,1,1,N,"Mr ZACHARY KAPLAN">> test.txt'
>>> re.sub( r"ECHO\s*(.*?)>>\s*test.txt", r"\1", text )
'A41,35,0,a,1,1,N,"Mr ZACHARY KAPLAN"'

do this for all lines in the file:

import re
f = open("input.bat")
of = open("output.txt", "w" )
for line in f:
    of.write( re.sub( r"ECHO\s*(.*?)>>\s*test.txt", r"\1", line ) )

I didn't test this code ...

hasen j
+3  A: 

Try this:

Put an ECHO OFF at the top of the batch file.

Then change each line to:

ECHO A41,35,0,a,1,1,N,"Mr ZACHARY KAPLAN"

and call your batch file:

mybatch.bat >> test.txt

Edit the first line to remove the echo off print out.

kgiannakakis
If you used @ECHO OFF you would not have to edit the first line. of the text file.
Justin
A: 

The thing is I don't want any client side applications