Optimization of a batch file that prints 30,000 lines of text to a file
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
source to share
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 ...
source to share
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
source to share