Batch to pull specific information from text

October 6, 2010 at 07:42:35
Specs: Windows XP
I have a text document sent down to me with a huge list of people on it and some of thier information. I need a batch to search through the text file. Pick out the information for each person and save it to it's own text file. The name it saves the text file as does not matter as long as each person is saved seperatly. Each persons information starts with the line "personal information" and continues down from there for the next twenty lines. So what I need the batch for is to search for the line "Personal information" copy it and the next twenty lines to a text file then search for the next line that says "Personal information" copy that twenty lines and so on. I've been trying to figure out how to do this and am a little lost to be honest. Do any of you batch gods have a suggestion I could try?

See More: Batch to pull specific information from text

Report •

#1
October 6, 2010 at 18:23:36
download grep for windows ,then do this

grep -A20 "Personal information" file

GNU win32 packages | Gawk


Report •

#2
October 7, 2010 at 06:12:09
That would be nice but, I con not install grep here at the office..

Report •

#3
October 7, 2010 at 07:28:56
download at home or somewhere else, its only a .exe file. Then bring to your office.

GNU win32 packages | Gawk


Report •

Related Solutions

#4
October 7, 2010 at 07:53:03
I can download it but, I can not install it. Nor, will the admins let me. I'll keep trying with batch. I can get single lines but not the lines following or will it continue on to the rest of the document. I've tried scripts in word to but, I'm completely lost there.

Report •

#5
October 7, 2010 at 08:08:37
then use this vbscript
Set objFS = CreateObject( "Scripting.FileSystemObject" )
strFileName = WScript.Arguments(0)
N=WScript.Arguments(1)
strPat=WScript.Arguments(2)
Set objFile = objFS.OpenTextFile(strFileName)
Do Until objFile.AtEndOfStream    
    linenum=objFile.Line
    strLine = objFile.ReadLine
    If InStr(strLine,strPat)> 0 Then
    	WScript.Echo strLine
    	For i=1 To N 
    		strLine = objFile.ReadLine
    		WScript.Echo strLine
    	Next
    End If 
Loop  	   

usage:

C:\test>cscript //nologo myscript.vbs file 20 "Personal information"

GNU win32 packages | Gawk


Report •

#6
October 7, 2010 at 11:54:52
Ghostdog,

I appreciate your help. Needless to say they don't have VB installed corectly for me to do that but, I've been doing some studying with word macros these last two days and was able to get what I needed. Thanks again for your help!


Report •

Ask Question