Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word - Delete lines not containing string 1

Status
Not open for further replies.
Apr 27, 2006
126
GB
Hi,

I have been passed several files which are each around 15MB of plain text (about 300,000 lines), I need to filter it down to only contain lines which contain a certain string.

e.g. Document:
Code:
some random stuff
Date: 01/01/08
other random stuff
this is elephant speaking
moo moo moo
Date: 02/01/08
yellow makes my eyes bleed
where is the elephant
moo

would output:
Code:
Date: 01/01/08
this is elephant speaking
Date: 02/01/08
where is the elephant

It seems simple enough to FIND the rows that contain a certain string and delete those lines.. but I want to delete all rows which don't contain those strings and be left with a list I can work with (will most likely end up dumping into excel or access but that's not for you to worry about for now :p )

Thanks for any advice

________
clueless
 

If that's just '15MB of plain text', why don't you open it as a text file, read line by line, and write what you want into another text file.
Code:
Open "C:\To.txt" For Output As #2
Open "C:\From.txt" For Input As #1
Do While Not EOF(1)   [green]'Loop until end of file.[/green]
   Line Input #1, strTextLine   [green]' Read line into variable.[/green]
   If strTextLine Is Good Then
      Print #2, strTextLine
   End If
Loop
Close #1
Close #2

Have fun.

---- Andy
 
You're the man! Cheers.

I had thought of something similar a short while ago but it was involving grabbing the line and pasting it somewhere else.. your idea wins :D

________
clueless
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top