batch file not counting the number of lines in1gb .txtfile

May 13, 2012 at 14:14:44
Specs: Windows Server 2003
I wrote a batch file for counting the number of lines in a text file using set /a count
and inside for loop incrementing the count.It is working fine for all files upto 700MB size.But after this size it is not counting the lines .It returns count as 0.Please advise.The text file from which I am taking count has more than 6 lakhs lines.

See More: batch file not counting the number of lines in1gb .txtfile

Report •

May 13, 2012 at 18:18:50
It would help a great deal if you could post the batch file you are using. Otherwise it is all just guesswork.

Report •

May 14, 2012 at 04:05:37
file = test.txt
set /a c=0
for /f "delims=" in %%i in (!file!) do set /a c = c+1

This is the code.But is there any maximum size limitation for the variable file

Report •

May 14, 2012 at 05:37:53
Environment variables do have a maximum size but it isn't a fixed value. All environment variables of a process must fit within a contiguous block within the process virtual address space which is a maximum of 2 GB. Because this block must be shared by many other things I would not be surprised at a 700 MB limit for an environment variable.

I think you will have to find a different way. I am not a batch file expert.

Report •

Related Solutions

May 14, 2012 at 09:26:01
A file must fit within the memory space, as LMiller7 notes. If it's too big, FOR will fail, possibly with an error. Numbers are stored as strings, but are converted into 32-bit signed integers for numerical calculations. This gives numbers an upper limit of 231 - 1 = 2,147,483,647.

As for your code, I attempted to test it out on a 700 MB file with 244,667,733 lines, and ended up getting bored after an hour. I suggest the following:

for /f %%a in ('type test.txt ^| find /v /c ""') do set c=%%a

How To Ask Questions The Smart Way

Report •

Ask Question