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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read Textfile Backwards??? 1

Status
Not open for further replies.

Stocki17

Programmer
Aug 4, 2005
3
AT
hello everybody!
i hope you understand what i write
because i´m form germany and i´m very bad in english

i have a problem in vbscript.

there is a log file of a data base, with rather much entries.
i want to check the LAST lines (you can choose how much lines you want to check) of these file if there is a line in which stands "ORA-......"
so the program works already.

BUT each line of this file gets an entry on an array.
so the file is very long and this leads to an very big array with much entrys.
but i don´t need all entrys, because i only want to check the last (for example 100 )lines of this file.

Now to my QUESTION.
is it possible to read this file starting backwards.
so because then the array is as big as i need it.
(then just the lines i want to check will be entried in this array)

in C i konw how to read a file starting backwards.
but i don´t find it how to do this in VbScript.

pleas help me if you know how to do this
Stocki
 
Sure you can do this.

For X = UBound(Array) to UBound(Array)-99
Line = Array(X)
Next


Or if you want to start reading forward

For X = (UBound(Array)-99) to UBound(Array)
Line = Array(X)
Next

I hope you find this post helpful.

Regards,

Mark
 
>BUT each line of this file gets an entry on an array.
>so the file is very long and this leads to an very big array with much entrys.
>but i don´t need all entrys, because i only want to check the last (for example 100 )lines of this file.
There is this concern which is legitimate maybe less for the reason of (memory) resources nowaday than for efficiency.

This is a way of how you can handle using ado recordset with oledb with extended properties setting.
[tt]
pathspec="d:\test\db\" 'your input
filename="errlog.txt" 'your input, extension has catches

set conn=createobject("adodb.connection")
set rs=createobject("adodb.recordset")

sconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & pathspec & ";" & _
"Extended Properties=""text;HDR=No"""
conn.open sconn

squery="select * from " & filename
rs.open squery,conn,3,3,1

dim adata()
redim adata(-1)
icount=0
rs.movelast
do until rs.bof or lnum>99
redim preserve adata(icount)
adata(icount)=rs.fields(0).value
rs.move -1
icount=icount+1
loop

rs.close
set rs=nothing
conn.close
set conn=nothing

'here adata contains the last 100 lines in reverse with the actual number of line read be ubound(adata)+1. adata(0) be the last line of data. Order reading can of course be done with
' for i=ubound(adata) to 0 step -1
' 'etc etc
' next
[/tt]
Just a further note if you are not familiar with this ado setup. If your log file is having extension commonly known like txt, csv, tab, tmp etc, it normally is okay without further twist. If not you may have to set up special extension through the registry for line reading --- for comma delimited or tab delimited or fixed length things, you can do without another device of schema.ini, but that's some other story not concerning here.

- tsuji
 
Correction:
[tt]>do until rs.bof or lnum>99[/tt]
should be read
[tt]do until rs.bof or [red]icount[/red]>99[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top