Optimization of a batch file that prints 30,000 lines of text to a file

I have a batch file that does this.

ECHO A41,35,0, a, 1,1, N, "Mr. ZACHARY KAPLAN" β†’ test.txt

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

Is there a way to speed this up?

/ Jeanre

0


source to share


5 answers


Try the following:

Place 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 the batch file:

mybatch.bat -> test.txt

Edit the first line to remove the echo fingerprint.

+3


source


If you do this it will be faster:



JAM DO %%Fo CAt Pa (set /p %yodo%=jol)

RUn

      

+2


source


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

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

Even a small qbasic program should be able to strip data between echo and β†’ and write it to a text file faster than your current method.

-Adam

+1


source


you can use scripting language to split the leading ECHO and trailing -> test.txt with a little regex

here is 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 have not tested this code ...

+1


source


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

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

You can also use BufferedReader and BufferedWriter

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

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

0


source







All Articles