Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Parse through a TXT file in reverse order

Hi!

I need to parse through a text file in reverse order using VBA. Any ideas
on how to do this? The text file can grow very large (10GB), so starting
at the beginning and inputting all the way to the end is not an attractive
option.

I'm trying to find the most recent ten occurrences of a certain message in
the log (which would be the last ten occurrences of said message in the
log).

I can handle the instr to find the message, and an array to store the
results, it's the backwards stepping that I can't figure out.

Thanks!!!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Parse through a TXT file in reverse order

How are you reading your data in? (code example perhaps)

how do you determine if it is a certain message

is a message all on one line?

--
Regards,
Tom Ogilvy


"JM" wrote in message
...
Hi!

I need to parse through a text file in reverse order using VBA. Any ideas
on how to do this? The text file can grow very large (10GB), so starting
at the beginning and inputting all the way to the end is not an attractive
option.

I'm trying to find the most recent ten occurrences of a certain message in
the log (which would be the last ten occurrences of said message in the
log).

I can handle the instr to find the message, and an array to store the
results, it's the backwards stepping that I can't figure out.

Thanks!!!




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Parse through a TXT file in reverse order

Hi Tom,

I didn't want to post code because I'm not tied to any one approach, and
didn't want to limit anyone's creativity. I typically use the Open for
Input approach, but am open to FSO too.

If parsing a file forwards, I typically would do something like this:

Do Until EOF(in)
Line Input #in, sLine
If Instr(1,sLine,"critical") 0 then
'(print the record to a worksheet or another text file)
End If
Loop

This particular log file is too big for this approach. I thought about
setting the seek point equal to the filelen, but I don't know how long a
line is, and where to set it for the prior line, and then to the line prior
to that, and so on.

Thanks!!


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Parse through a TXT file in reverse order

Dim vArr() as String
ReDim vArr(1 to 1000)
Dim i as Long, j as Long

i = 1
Do Until EOF(in)
Line Input #in, sLine
If Instr(1,sLine,"critical") 0 then
varr(i) = sLine
i = i + 1
End If
Loop

for j = i-1 to j-10 step -1
debug.print print varr(j)
Next


if your lines are fixed length, then you might be able to handle it as a
random access file. If not, then the sequential method above is what I can
think about. You might be able to approach it as an ADO record set and
then query it as a database, but I haven't done any work in that area.

--
Regards,
Tom Ogilvy


"JM" wrote in message
...
Hi Tom,

I didn't want to post code because I'm not tied to any one approach, and
didn't want to limit anyone's creativity. I typically use the Open for
Input approach, but am open to FSO too.

If parsing a file forwards, I typically would do something like this:

Do Until EOF(in)
Line Input #in, sLine
If Instr(1,sLine,"critical") 0 then
'(print the record to a worksheet or another text file)
End If
Loop

This particular log file is too big for this approach. I thought about
setting the seek point equal to the filelen, but I don't know how long a
line is, and where to set it for the prior line, and then to the line

prior
to that, and so on.

Thanks!!




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Parse through a TXT file in reverse order

It looks like your code is starting at the beginning and is moving in
forward order..? These log files get so big that I was hoping to start at
the end and move backwards.



"Tom Ogilvy" wrote in message
...
Dim vArr() as String
ReDim vArr(1 to 1000)
Dim i as Long, j as Long

i = 1
Do Until EOF(in)
Line Input #in, sLine
If Instr(1,sLine,"critical") 0 then
varr(i) = sLine
i = i + 1
End If
Loop

for j = i-1 to j-10 step -1
debug.print print varr(j)
Next


if your lines are fixed length, then you might be able to handle it as a
random access file. If not, then the sequential method above is what I

can
think about. You might be able to approach it as an ADO record set and
then query it as a database, but I haven't done any work in that area.

--
Regards,
Tom Ogilvy


"JM" wrote in message
...
Hi Tom,

I didn't want to post code because I'm not tied to any one approach, and
didn't want to limit anyone's creativity. I typically use the Open for
Input approach, but am open to FSO too.

If parsing a file forwards, I typically would do something like this:

Do Until EOF(in)
Line Input #in, sLine
If Instr(1,sLine,"critical") 0 then
'(print the record to a worksheet or another text file)
End If
Loop

This particular log file is too big for this approach. I thought about
setting the seek point equal to the filelen, but I don't know how long a
line is, and where to set it for the prior line, and then to the line

prior
to that, and so on.

Thanks!!








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default Parse through a TXT file in reverse order


Tom Ogilvy wrote:
You might be able to approach it as an ADO record set and
then query it as a database, but I haven't done any work in that

area.

See:

http://msdn.microsoft.com/library/de...ng03092004.asp

Note that a row in a text file cannot be amended (UPDATE SQL DML) or
deleted (DELETE) using SQL/ADO, but can be queried (SELECT) and new
rows appended to the end of the file (INSERT INTO).

Jamie.

--

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I reverse name order from Last, First to First Last in Exc Annie Lord Excel Discussion (Misc queries) 4 April 22nd 23 02:10 AM
Reverse Row Order? trvlnmny New Users to Excel 3 May 30th 10 08:22 AM
Reverse Order PL Excel Discussion (Misc queries) 3 July 1st 09 05:01 AM
"Open File" listed in reverse-alphabetical order. Jason[_13_] Excel Discussion (Misc queries) 4 January 8th 09 01:43 PM
reverse order Lamb Chop Excel Discussion (Misc queries) 2 June 20th 06 03:37 PM


All times are GMT +1. The time now is 03:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"