timi1014 Posted June 25, 2012 Share Posted June 25, 2012 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! Link to comment Share on other sites More sharing options...
abberration Posted June 25, 2012 Share Posted June 25, 2012 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) Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
UEZ Posted June 25, 2012 Share Posted June 25, 2012 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Mechaflash Posted June 25, 2012 Share Posted June 25, 2012 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.” Link to comment Share on other sites More sharing options...
Spiff59 Posted June 25, 2012 Share Posted June 25, 2012 (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 June 26, 2012 by Spiff59 Link to comment Share on other sites More sharing options...
iamtheky Posted June 25, 2012 Share Posted June 25, 2012 (edited) one more.. yay, new ff, new pasting issues.... Edited June 25, 2012 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
GEOSoft Posted June 26, 2012 Share Posted June 26, 2012 $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!" Link to comment Share on other sites More sharing options...
Mechaflash Posted June 26, 2012 Share Posted June 26, 2012 $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.” Link to comment Share on other sites More sharing options...
GEOSoft Posted June 26, 2012 Share Posted June 26, 2012 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!" Link to comment Share on other sites More sharing options...
Juvigy Posted June 27, 2012 Share Posted June 27, 2012 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 ..." Link to comment Share on other sites More sharing options...
UEZ Posted June 27, 2012 Share Posted June 27, 2012 @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. 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Mechaflash Posted June 27, 2012 Share Posted June 27, 2012 C'mon guys , dont do 'everything' in 5 ways for the guyMore 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.” Link to comment Share on other sites More sharing options...
timi1014 Posted June 28, 2012 Author Share Posted June 28, 2012 Thanks to all off you! i am going to find the best func that match my requirements. never expected such high response O.o Link to comment Share on other sites More sharing options...
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