Skorn Posted September 19, 2005 Posted September 19, 2005 (edited) Hello all, I am working on a script that filters out a specific IP from a logfile and saves it to an array. It then should write that array to a file. But I am getting an error that I can't fix, any help is appreciated. Thanks Line 19 Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded expandcollapse popup#include <File.au3> ;temp[0] = number of cols ;temp[n] 1 = date time, 2=ip, 3=user(reg users), 4=some #, 5=req/fail, 6=url $in_filename = FileOpenDialog("Select Logfile",@ScriptDir,"Files (*.log)",5) Dim $lines, $Display, $NumCols, $log Global $save[100][4]; ie-save[1][1]=line 1+date, save[1][2]=line 1+url _FileReadToArray($in_filename, $lines) ;$NumCols=$temp[0] $ipadd="10.10.10.10";ip address to extract from file for $x = 1 to $lines[0] $temp = StringSplit($lines[$x], Chr(9)); Found columns number @TAB ;MsgBox(4096, "2",$temp[2]); for testing if $temp[2]=$ipadd then; if current line matches ip then save line to array $save[$x]=$temp[1] & " " & $temp[2] & " " & $temp[6];time+ip+url endif next ;Write to file $file = FileOpen( $ipadd&".txt", 1) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf for $y = 1 to $lines[0] FileWrite($file, $save[$y]) next FileClose($file) Here's an example of the input logfile, fields are supposed to be seperated by tab. 04/12/05 04:34:05 10.10.10.14 reg users 0000000136 Requested: SSL://v5.windowsupdate.microsoft.com:443 04/12/05 04:34:08 10.10.10.14 reg users 0000000137 Requested: http://rs.windowsupdate.microsoft.com/odf/v5odf.xml 04/12/05 04:36:15 10.10.10.10 reg users 0000000139 Failed authorisation: http://au.download.windowsupdate.com/ 04/12/05 04:36:15 10.10.10.10 reg users 0000000139 Requested: http://au.download.windowsupdate.com/ 04/12/05 04:38:45 10.10.10.14 reg users 0000000140 Failed authorisation: http://test.com Edited September 19, 2005 by Skorn
seandisanti Posted September 19, 2005 Posted September 19, 2005 Hello all, I am working on a script that filters out a specific IP from a logfile and saves it to an array. It then should write that array to a file. But I am getting an error that I can't fix, any help is appreciated.ThanksLine 19 Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded#include <File.au3> ;temp[0] = number of cols ;temp[n] 1 = date time, 2=ip, 3=user(reg users), 4=some #, 5=req/fail, 6=url $in_filename = FileOpenDialog("Select Logfile",@ScriptDir,"Files (*.log)",5) Dim $lines, $Display, $NumCols, $log Global $save[100][4]; ie-save[1][1]=line 1+date, save[1][2]=line 1+url _FileReadToArray($in_filename, $lines) ;$NumCols=$temp[0] $ipadd="10.10.10.10";ip address to extract from file for $x = 1 to $lines[0] $temp = StringSplit($lines[$x], Chr(9)); Found columns number @TAB ;MsgBox(4096, "2",$temp[2]); for testing if $temp[2]=$ipadd then; if current line matches ip then save line to array $save[$x]=$temp[1] & " " & $temp[2] & " " & $temp[6];time+ip+url endif next ;Write to file $file = FileOpen( $ipadd&".txt", 1) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf for $y = 1 to $lines[0] FileWrite($file, $save[$y]) next FileClose($file)Here's an example of the input logfile, fields are supposed to be seperated by tab.04/12/05 04:34:05 10.10.10.14 reg users 0000000136 Requested: SSL://v5.windowsupdate.microsoft.com:443 04/12/05 04:34:08 10.10.10.14 reg users 0000000137 Requested: http://rs.windowsupdate.microsoft.com/odf/v5odf.xml 04/12/05 04:36:15 10.10.10.10 reg users 0000000139 Failed authorisation: http://au.download.windowsupdate.com/ 04/12/05 04:36:15 10.10.10.10 reg users 0000000139 Requested: http://au.download.windowsupdate.com/ 04/12/05 04:38:45 10.10.10.14 reg users 0000000140 Failed authorisation: http://test.comwould something like this suit your needs?$in_filename = FileOpenDialog("Select Logfile",@ScriptDir,"Files (*.log)",5) $file = FileOpen($in_filename,0) $output = FileOpen("c:\blah.txt",1) $ipadd="10.10.10.10";ip address to extract from file while 1 $line = FileReadLine($file) if @error = -1 then ExitLoop if StringInStr($line,$ipadd) Then FileWriteLine($output,$line) EndIf WEnd FileClose($file) FileClose($output)just seems easier to do that way...
Skorn Posted September 19, 2005 Author Posted September 19, 2005 would something like this suit your needs?$in_filename = FileOpenDialog("Select Logfile",@ScriptDir,"Files (*.log)",5) $file = FileOpen($in_filename,0) $output = FileOpen("c:\blah.txt",1) $ipadd="10.10.10.10";ip address to extract from file while 1 $line = FileReadLine($file) if @error = -1 then ExitLoop if StringInStr($line,$ipadd) Then FileWriteLine($output,$line) EndIf WEnd FileClose($file) FileClose($output)just seems easier to do that way...brilliant, works like a charm. Thank you sir!
seandisanti Posted September 19, 2005 Posted September 19, 2005 brilliant, works like a charm. Thank you sir! np, glad i could help.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now