Sign in to follow this  
Followers 0
timi1014

add numbers to different IP´s

13 posts in this topic

Hey Community!

It´s been a while but now i realy need your help.

i have a .txt looking like that

192.168.0.112 smbprn.00 1

192.168.0.112 smbprn.00 1

192.168.0.112 smbprn.00 1

192.168.0.112 smbprn.00 1

192.168.0.119 smbprn.00 1

192.168.0.119 smbprn.00 2

192.168.0.119 smbprn.00 1

192.168.0.119 smbprn.00 1

192.168.0.119 smbprn.00 1

192.168.0.119 smbprn.00 1

192.168.0.119 smbprn.00 1

192.168.0.119 smbprn.00 3

192.168.0.119 smbprn.00 1

192.168.0.119 smbprn.00 1

192.168.0.119 smbprn.00 1

192.168.0.134 smbprn.00 1

192.168.0.136 smbprn.00 9

192.168.0.136 smbprn.00 9

192.168.0.136 smbprn.00 4

it´s the output from a printing software.

The last number is the number of pages an IP print.

so i need to add all pages together to the right IP.

there can be differnt IP´s from 30 to 200

i dont need a working script but i dont know how to start some useful tips would be great!

Share this post


Link to post
Share on other sites



Maybe this will help get you started:

#include <array.au3>
#include <file.au3>

$lineCount = _FileCountLines("data.txt")
Dim $outputArray[$lineCount][2]
For $i = 1 to $lineCount Step 1
$line = FileReadLine("data.txt", $i)
$line = StringStripWS($line, 8)
$split = StringSplit($line, "smbprn.00", 3)
$outputArray[$i - 1][0] = $split[0]
$outputArray[$i - 1][1] = $split[1]
Next

_ArrayDisplay($outputArray)

RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

Something like that?

#include <Array.au3>
$sFile = FileRead(@ScriptDir & "Printer.txt")
$aIPs = StringRegExp($sFile, "(?:d{1,3}.){3}d{1,3}", 3)
$aUniqueIPs = _ArrayUnique($aIPs)
$iPos = $aUniqueIPs[0]
$aUniqueIPs[0] *= 2
ReDim $aUniqueIPs[$aUniqueIPs[0] + 1]
$aValues = StringRegExp($sFile & @CRLF, "((?:d{1,3}.){3}d{1,3}).*(d+)rn", 3)

For $i = 0 To UBound($aValues) - 1 Step 2
    $aUniqueIPs[$iPos + _ArraySearch($aUniqueIPs, $aValues[$i])] += $aValues[$i + 1]
Next

For $i = 1 To $aUniqueIPs[0] / 2
    ConsoleWrite($aUniqueIPs[$i] & ": " & $aUniqueIPs[$iPos + $i] & @LF)
Next

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

More lines of code, but you can drop having to parse file.au3 (more native). This method should work a little faster.

#include <array.au3>

$sFile = "C:print.txt"
$hFile = FileOpen($sFile) ; open for reading
Local $x = 0, $i = 0, $asPrintCount[171][2]
While 1
    $i+=1
    $sLine = FileReadLine($hFile, $i)
    If @error <> 0 Then ExitLoop
    $asSplit = StringSplit($sLine, " ")
    $iIndex = _ArraySearch($asPrintCount, $asSplit[1], 0, 0, 0, 0, 1, 0)
    If $iIndex = -1 Then
        $asPrintCount[$x][0] = $asSplit[1]
        $asPrintCount[$x][1] = $asSplit[$asSplit[0]]
        $x+=1
    Else
        $asPrintCount[$iIndex][1]+=$asSplit[$asSplit[0]]
    EndIf
WEnd
FileClose($hFile)
ReDim $asPrintCount[$x][2]
_ArrayDisplay($asPrintCount)

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

And another...

#include <Array.au3>
#include <File.au3>

Global $aFileIn, $iReportLines
_FileReadToArray(@ScriptDir & "Printer.txt",$aFileIn)
Global $aReportOut[$aFileIn[0] + 1][2]

For $x = 1 to $aFileIn[0]
    $aTemp = StringSplit($aFileIn[$x], " ", 0)
    If $aTemp[1] <> $aReportOut[$iReportLines][0] Then $iReportLines += 1
    $aReportOut[$iReportLines][0] = $aTemp[1] ; IP address
    $aReportOut[$iReportLines][1] += $aTemp[$aTemp[0]] ; IP page total
    $aReportOut[0][1] += $aTemp[$aTemp[0]] ; Overall page total
Next

$aReportOut[0][0] = $iReportLines ; Number of IP's
ReDim $aReportOut[$iReportLines + 1][2]
_ArrayDisplay($aReportOut)

Edit: Added one line for an overall page total

Edited by Spiff59

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

one more..

yay, new ff, new pasting issues....

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

$FileIn = "C:SomePathsomefile.txt"
$s_Str = _TotalPages(FileRead($FileIn))

MsgBox(4096, "Result",  $s_Str)
 
Func _TotalPages($s_Txt)
      If FileExists($s_Txt) Then $s_Txt = FileRead($s_Txt)
      Local $int_Count = 0
      Local $a_Hold = StringRegExp($s_Txt, ".+h+(d+)", 3)
      If Not @Error Then
            For $i = 0 To Ubound($a_Hold) -1
                  $int_Count += $a_Hold[$i]
            Next
            Return "Total Page Count: " & $Int_Count
      EndIf
      Return SetError(1, 0, "Error creating the array.")
EndFunc


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

$FileIn = "C:SomePathsomefile.txt"
$s_Str = _TotalPages(FileRead($FileIn))

MsgBox(4096, "Result", $s_Str)

Func _TotalPages($s_Txt)
     If FileExists($s_Txt) Then $s_Txt = FileRead($s_Txt)
     Local $int_Count = 0
     Local $a_Hold = StringRegExp($s_Txt, ".+h+(d+)", 3)
     If Not @Error Then
         For $i = 0 To Ubound($a_Hold) -1
                 $int_Count += $a_Hold[$i]
         Next
         Return "Total Page Count: " & $Int_Count
     EndIf
     Return SetError(1, 0, "Error creating the array.")
EndFunc

From now on, I'm going to be one of the cool kids and write my examples in functions. It's how it should be done anyways. <3 Geo

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

Just easier to follow that way.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

C'mon guys , dont do 'everything' in 5 ways for the guy , just point to the right direction.

"Give a man a fish .... Teach the man to fish ..."

Share this post


Link to post
Share on other sites

@Juvigy: we showed him how to fish 5 different fishes and now it is timi1014's turn to learn from these examples and learn fishing. :D

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

C'mon guys , dont do 'everything' in 5 ways for the guy

More than one way to skin a program?


Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

Thanks to all off you!

i am going to find the best func that match my requirements.

never expected such high response O.o

Share this post


Link to post
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
Sign in to follow this  
Followers 0