Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3025
  • Last Modified:

Dos Batch Program to Parse Text File

I need to write a batch program that will scan a text file and write out the first 5000 lines that contain "000000000000".  The file contans around 14 million rows.
0
ddpleasant
Asked:
ddpleasant
1 Solution
 
Shift-3Commented:
Paste the script below into a text file with a .cmd extension.  Customize the value of the file variable with the location of the text file.  Running the script will echo the first 5000 matching lines to the file specified in the output variable.

I've only been able to test this with a 100,000-line file.  It's quite possible that it will choke on one that's 14 million lines.  Special characters such as angle brackets, pipes, and ampersands will also give it trouble.


@echo off
setlocal enabledelayedexpansion
 
set file=c:\file.txt
set output=output.txt
set maxlines=5000
 
set count=0
 
for /F "tokens=* usebackq" %%G in ("%file%") do (
 if !count!==%maxlines% goto :eof
 
 set line=%%G
 set line=!line:*000000000000=--FOUND--!
 if "!line:~0,9!"=="--FOUND--" (
  echo %%G>>"%output%"
  set /a count+=1
 )
)

Open in new window

0
 
ddpleasantAuthor Commented:
You were right about it choking.  I received a mesage that stated not enough storage is available to process this command.

Thank you for the help though.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now