?
Solved

Dos Batch Program to Parse Text File

Posted on 2008-10-23
2
Medium Priority
?
2,999 Views
Last Modified: 2008-10-24
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
Comment
Question by:ddpleasant
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 2000 total points
ID: 22789252
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
 

Author Comment

by:ddpleasant
ID: 22789340
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question