Ese Posted December 21, 2008 Share Posted December 21, 2008 Hello i'm trying with no success.. to do thisi have a simple txt file with usernames looks like this:EseBlesenasulinroymeyouetcand i have a log file with a lot of information. i need to take the first user and see how many times it appears in the log file. and output it somehow.take the second user and do the same and so on...Any help would be appriciatedCheers Link to comment Share on other sites More sharing options...
BrettF Posted December 21, 2008 Share Posted December 21, 2008 Post your code and a sample of the files. Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
GEOSoft Posted December 21, 2008 Share Posted December 21, 2008 (edited) $File_1 = "Path\somefile.txt" $File_2 = FileRead("Path\AnotherFile.txt") $aArray = _StringToArray2($File_1) For $i = 0 To Ubound($aArray)-1 $sTest = StringReplace($File_2, $aArray[$i], $aArray[$i]) MsgBox( 4096, "Results", "The name appeared " & @Extended & " times") Next Func _StringToArray2($sStr) If FileExists($sStr) Then $sStr = FileRead($sStr) If $sStr = "" Then Return SetError(1);; Empty strings not allowed Local $aRegEx = StringRegExp($sStr, "(?i)(.*)(?:\z|\r\n|\r|\n)", 3) If @Error Then Return SetError(2);; RegExp failed Return $aRegEx EndFunc Edited December 21, 2008 by GEOSoft 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...
Ese Posted December 21, 2008 Author Share Posted December 21, 2008 a sample of the users file is above, the second file is just some normal log I'm thinking of something: $file = FileOpen("filename.txt", 0) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop MsgBox(0, "Test:", $line) \\\ maybe insted of this line a code to search in the log file and return the times it appears...? Wend but not sure. cheers Link to comment Share on other sites More sharing options...
GEOSoft Posted December 21, 2008 Share Posted December 21, 2008 (edited) FileReadLine is the slowest possible method of reading the contents of a file The code I gave you reads it to an array first and then loops through the array using StringReplace("String", "Text", "Text") which equates to no change in the file because we just read the second file into a variable anyway, and uses the @Extended to find out how many times the string was "replaced" with the same string. Edit: Here is a quick example of what would happen $sStr = "Is Jos doing something that Jos shouldn't be doing? Have a great day doing it Jos." StringReplace($sStr, "Jos", "Jos") MsgBox (4096, "Results", "Jos was mentioned " & @Extended & " times in the string.") ;;@Extended would return 3 so the message box would read ;; Jos was mentioned 3 times in the string. Edited December 21, 2008 by GEOSoft 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...
Ese Posted December 21, 2008 Author Share Posted December 21, 2008 Cheers for that mate Link to comment Share on other sites More sharing options...
GEOSoft Posted December 21, 2008 Share Posted December 21, 2008 Here is a function that I have on my website that does exactly what I posted above. ;=============================================================================== ; Function Name: _StringGetChrCount() ; Description: Count the number of times a given character appears in a string ; Syntax: ; Parameter(s): $cStr - The string to check ; $cChr - The character to count ; ; Requirement(s): ; Return Value(s): The number of times a character appears in a string ; Author(s): George (GEOSoft) Gedye ; Modification(s): ; Note(s): Can also be used to determine how many times a string appears in a file ; by using FileRead() for $cStr and the string for $cChar ; Example(s): $Test = _StringGetChrCount("This is just an example.", Chr(32)) ; Since Chr(32) is a space then it would return 4 ;=============================================================================== Func _StringGetChrCount($cStr, $cChr, $iCase = 0) If $iCase <> 0 Then $iCase = 1 StringReplace($cStr, $cChr, $cChr, 0, $iCase) Return @Extended EndFunc ;<==> _StringGetChrCount() 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...
GEOSoft Posted December 21, 2008 Share Posted December 21, 2008 (edited) Actually this is even better because it will check word boundaries. Example: If the name was Jos then the origional would also count Joseph. This one won't do that $File_1 = "Path\somefile.txt" $File_2 = FileRead("Path\AnotherFile.txt") $aArray = _StringToArray2($File_1) For $i = 0 To Ubound($aArray)-1 $sTest = StringRegExpReplace($File_2, "(?i)\b(" & $aArray[$i] & ")\b", "$1") MsgBox( 4096, "Results", "The name appeared " & @Extended & " times") Next Func _StringToArray2($sStr) If FileExists($sStr) Then $sStr = FileRead($sStr) If $sStr = "" Then Return SetError(1);; Empty strings not allowed Local $aRegEx = StringRegExp($sStr, "(?i)(.*)(?:\z|\r\n|\r|\n)", 3) If @Error Then Return SetError(2);; RegExp failed Return $aRegEx EndFunc Edited December 21, 2008 by GEOSoft 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...
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