Jump to content

Where named array?


Inververs
 Share

Recommended Posts

There is a log file to read:

192.168.0.1 5

192.168.0.2 6

192.168.0.5 10

192.168.0.4 15

...

...

192.168.0.1 2

192.168.0.5 8

here ip address, then the number of clicks.

Rows in the file may be greater than 10 thousand

How quickly count the number of clicks for each ip address? ...need to use _ArraySearch() or there is another way????

Link to comment
Share on other sites

  • Moderators

There is a log file to read:

192.168.0.1 5

192.168.0.2 6

192.168.0.5 10

192.168.0.4 15

...

...

192.168.0.1 2

192.168.0.5 8

here ip address, then the number of clicks.

Rows in the file may be greater than 10 thousand

How quickly count the number of clicks for each ip address? ...need to use _ArraySearch() or there is another way????

We could easily show you a regular expression to do it... but how would you know what IP went with the clicks?

#include <array.au3>
Local $s_text = FileRead("logfile.log")
Local $s_pattern = "(\d+\.\d+\.\d+\.\d+) (\d+)"
Local $a_sre = StringRegExp($s_text, $s_pattern, 3); Every other one will be the number of clicks
_ArrayDisplay($a_sre)
Local $a_2d_array[((Ubound($a_sre) - 1) / 2) + 1][2], $i_add = 0
For $i = 0 To Ubound($a_sre) - 1 Step 2
    $a_2d_array[$i_add][0] = $a_sre[$i]; IP Address
    $a_2d_array[$i_add][1] = $a_sre[$i + 1]; Clicks
    $i_add += 1
Next
_ArrayDisplay($a_2d_array)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

This is not exactly what I need

For example

192.168.0.1 4

192.168.0.1 2

192.168.0.2 7

192.168.0.1 3

And as a result will be retrieved as follows (can be two-dimensional array)

192.168.0.1 9 (4 +2 +3)

192.168.0.2 7

ie to estimate how many clicks each ip

Regular Expressions =) I've got a nice tester in my sig.

Here use this:

([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)\s(.*)

Flag: 3

Array[0] = 192.168.0.1

Array[1] = 4

:)

Link to comment
Share on other sites

  • Moderators

Hey, for $50.00 I'll write the logic for you! :)

Seriously, I gave you a foundation, a 2D array even, now just go through them and match IPs and add their sub counterparts.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hi.

StringRegExp() is a good approach (as posted before)

If you don't like regex:

Dim $ArrayOne[1]

_FileReadToArray($Logfile,$ArrayOne)

will give you your logfile as an array.

Then use StringSplit() to separate the IP from the counted clicks.

Push this 2D result into a proper preDIMed 2nd 2D Array "ArrayTwo"

Then read

for $i=1 to UBound(ArrayTwo)-1

the 1st IP address [1,0], add the clicks [1,1] in a temporary counter throughout the full array.

Whenever you meet the IP again, count and set [n,0] and [n,1] to "" to mark them as done.

search for the next [n,0] that is not equal "", step through the rest of ArrayTwo.

:)

Now start coding it yourself >_<

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Array[0] = 192.168.0.1

Array[1] = 4

Array[2] = 192.168.0.1

Array[3] = 2

Array[4] = 192.168.0.2

Array[5] = 7

Array[6] = 192.168.0.1

Array[7] = 3

))) How make this?

Array[0][0]=192.168.0.1

Array[0][1]=9

Array[1][0]=192.168.0.2

Array[1][1]=7

:)

Meh here it is:

$Text = "192.168.0.1 4" & @CRLF & "192.168.0.2 2" & @CRLF &"192.168.0.3 7"

$Regex = StringRegExp($Text, "([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)\s(.*)", 3)
Local $RegExArray[(UBound($Regex) / 2)][2]
$NumberOfItems = UBound($Regex)
$Item = 0
For $I = 0 To $NumberOfItems - 2 Step 2 
    $RegExArray[$Item][0] = $Regex[$I]
    $RegExArray[$Item][1] = $Regex[$I + 1]
    $Item += 1
Next



MsgBox(0, "", $RegExArray[0][0])
MsgBox(0, "", $RegExArray[0][1])

Figure out how it works. So that you can do this stuff next time >_<

Link to comment
Share on other sites

  • Moderators

Meh here it is:

$Text = "192.168.0.1 4" & @CRLF & "192.168.0.2 2" & @CRLF &"192.168.0.3 7"

$Regex = StringRegExp($Text, "([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)\s(.*)", 3)
Local $RegExArray[(UBound($Regex) / 2)][2]
$NumberOfItems = UBound($Regex)
$Item = 0
For $I = 0 To $NumberOfItems - 2 Step 2 
    $RegExArray[$Item][0] = $Regex[$I]
    $RegExArray[$Item][1] = $Regex[$I + 1]
    $Item += 1
Next



MsgBox(0, "", $RegExArray[0][0])
MsgBox(0, "", $RegExArray[0][1])oÝ÷ ØX º·¨ºØhÂ+p¢¹,Jajܨ¹Æ§vaË-¹÷ç{mgþ«¨µäájÝý²z-Ø­v¬mi×m業æÉìb²Ø§*l¶¶«)>+,º²Ø§©Ý¶Æ޲Ȩ+½éå¢xاrëyËX¢íý­ë¬x(¦Ø¨©oj[³^Ø^­ç·§¢mÚö¥¹ëÙh¢H§ú+j|ªÚr׫§¶«zÈhºW[zåÉØ ×!j¶µêì#oy©ky§r¦º/׶¢ºÞr×±¦·¬²*'Ø­N¬É¨­ì!jÒ0¢é]v®¶­sb6æ6ÇVFRfÇC¶'&æS2fwC° ¤Æö6Âb33c·5öfÆRÒfÆU&VBgV÷C¶ÆövfÆRæÆörgV÷C² ¢b33c¶ö'&ÒôvWD6Æ6·2b33c·5öfÆR¥ô'&F7Æb33c¶ö'& ¤gVæ2ôvWD6Æ6·2b33c·5öfÆR Æö6Âb33c·5÷FWBÒb33c·5öfÆP bfÆTW7G2b33c·5öfÆRFVâb33c·5÷FWBÒfÆU&VBb33c·5öfÆR  Æö6Âb33c·5÷GFW&âÒgV÷C²b3#¶B²b3#²âb3#¶B²b3#²âb3#¶B²b3#²âb3#¶B²gV÷C° Æö6Âb33c¶÷7&RÒ7G&æu&VtWb33c·5÷FWBÂb33c·5÷GFW&âÂ2²vWBÆÂFR0 bW'&÷"FVâ6WDW'&÷"  ô'&VæVU6÷'Bb33c¶÷7&R  Æö6Âb33c¶÷V"ÒT&÷VæBb33c¶÷7&RÂb33c¶÷&WE²b33c¶÷V%Õ³%Ð Æö6Âb33c¶ö6Æ6·2Âb33c¶öfæEö6Æ6·0  f÷"b33c¶ÒFòb33c¶÷V"Ò b33c¶ö6Æ6·2Ò b33c¶öfæEö6Æ6·2Ò7G&æu&VtWb33c·5÷FWBÂ7G&æu&WÆ6Rb33c¶÷7&U²b33c¶ÒÂgV÷C²âgV÷C²ÂgV÷C²b3#²âgV÷C²fײgV÷C²b3#¶B²gV÷C²Â2 f÷"b33c¶âÒFòT&÷VæBb33c¶öfæEö6Æ6·2Ò b33c¶ö6Æ6·2³ÒçBb33c¶öfæEö6Æ6·5²b33c¶åÒ æW@ b33c¶÷&WE²b33c¶Õ³ÒÒb33c¶÷7&U²b33c¶Ð b33c¶÷&WE²b33c¶Õ³ÒÒb33c¶ö6Æ6·0 æW@  &WGW&âb33c¶÷&W@¤VæDgVæ0 ¤gVæ2ô'&VæVU6÷'B'&Vbb33c¶ö'&Âb33c¶öFW66VæFærÒÂb33c¶ö&6RÒÂb33c¶ö66RÒ b4'&b33c¶ö'&ÒFVâ&WGW&â6WDW'&÷"  Æö6Âb33c¶÷V"ÒT&÷VæBb33c¶ö'& bb33c¶÷V"ÒÒb33c¶ö&6RFVâ&WGW&âb33c¶ö'&  ô'&6÷'Bb33c¶ö'&Âb33c¶öFW66VæFærÂb33c¶ö&6R  Æö6Âb33c¶÷&WE²b33c¶÷V%ÒÂb33c¶öFBÒb33c¶ö&6P b33c¶÷&WE²b33c¶ö&6UÒÒb33c¶ö'&²b33c¶ö&6UÐ  f÷"b33c¶Òb33c¶ö&6R²Fòb33c¶÷V"Ò bb33c¶ö66RFVà bæ÷Bb33c¶ö'&²b33c¶ÒÒÓÒb33c¶ö'&²b33c¶ÒFVà b33c¶öFB³Ò b33c¶÷&WE²b33c¶öFEÒÒb33c¶ö'&²b33c¶Ð VæD` VÇ6P bæ÷Bb33c¶ö'&²b33c¶ÒÒÒb33c¶ö'&²b33c¶ÒFVà b33c¶öFB³Ò b33c¶÷&WE²b33c¶öFEÒÒb33c¶ö'&²b33c¶Ð VæD` VæD` æW@  bb33c¶öFBÒFVâ&WGW&â6WDW'&÷""  &TFÒb33c¶÷&WE²b33c¶öFB²Ð b33c¶ö'&Òb33c¶÷&W@  &WGW&âb33c¶÷&W@¤VæDgVæ
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...