DiskAI Posted October 19, 2005 Share Posted October 19, 2005 (edited) $file = "list.txt"$filea = FileOpen($file, 0)$i = 0While 1 $i = $i + 1 $line = FileReadLine($file,$i) If @error = -1 Then ExitLoop If StringInStr($line,"yahoo.com") Or StringInStr($line,"myspace.com") Or StringInStr($line,"hotmail.") Or StringInStr($line,"friendster.com") Or StringInStr($line,"login.passport") Or StringInStr($line,"file://") Or StringInStr($line,"premierleague") Or StringInStr($line,"soccernet") Or StringInStr($line,"ukm.my") Or StringInStr($line,"java script:") Or StringInStr($line,"uclfantasy") Or StringInStr($line,"about:") Or StringInStr($line,"My Computer") Or StringInStr($line,"jobstreet.com") Or StringInStr($line,"singingfool.com") Or StringInStr($line,"malaysiaairlines") Or StringInStr($line,"cyki") Or StringInStr($line,"ismgames") Or StringInStr($line,"uefa") Or StringInStr($line,"google.com") Or StringInStr($line,"smpweb") Or StringInStr($line,"ftp:") Or StringInStr($line,"sppk") Or StringInStr($line,"msn.") Or StringInStr($line,"jakionline") Or StringInStr($line,"trendmicro.com") Then ;;;Else FileWrite("_" & $file,$line & @CRLF) EndIfWendFileClose($file)SoundPlay("C:\WINDOWS\Media\ding.wav")MsgBox(0,"","Done")several questions1. how do i replace the "if stringinstr" bit so it wont be soooooo huge2. is there an better way to go about this script3. why the above script eats up a lot of resources cause i got txt files close to 1mb and it took a long time to processp/s : code looks rough ... i'm a chm guy (learn from help files ) Edited October 19, 2005 by DiskAI i think Link to comment Share on other sites More sharing options...
/dev/null Posted October 19, 2005 Share Posted October 19, 2005 (edited) several questions1. how do i replace the "if stringinstr" bit so it wont be soooooo huge2. is there an better way to go about this script3. why the above script eats up a lot of resources cause i got txt files close to 1mb and it took a long time to processp/s : code looks rough ... i'm a chm guy (learn from help files )here are some ideas. WARNING: Code not tested !!!1.) Use a function and pass the string arguments separated by a delimiter. Looks nicer...$pattern = "pattern1|pattern2|pattern3" if not _PatternFound($line, $pattern) then ; write line to new file else ; do something meaningfull or nothing at all :-) endif func _PatternFound($line,$pattern) local $stringarray = StringSplit($pattern, "|") local $counter for $counter = 1 to $stringarray[0] if StringInStr($line,$stringarray[$counter]) then return 1 next return 0 endfunc2.) Yes, read the whole file into an array. See: _FileReadToArray(). It's much faster than reading the whole file in one string. Then loop through the array to search the pattern in every line.3.) Reason: see 2.) String operations are slow when you apply them on a large stringEDIT: Fixed some errors in code.CheersKurt Edited October 19, 2005 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Nuffilein805 Posted October 19, 2005 Share Posted October 19, 2005 do a select case endselect but that just split its up in several lines e.g. select case not stringinstr ($line, "yahoo.com") filewrite ("_" & $file, $line & @crlf) case not stringinstr ($line, "myspace.com") filewrite ("_" & $file, $line & @crlf) endselect and your right your script uses quite a lot of ressources just is a bit more optical my little chatmy little encryption toolmy little hidermy unsafe clickbot Link to comment Share on other sites More sharing options...
Nuffilein805 Posted October 19, 2005 Share Posted October 19, 2005 damn it you've been faster i think he wants the function the other way round - if it's not found it shall do an action my little chatmy little encryption toolmy little hidermy unsafe clickbot Link to comment Share on other sites More sharing options...
DiskAI Posted October 19, 2005 Author Share Posted October 19, 2005 thanks kurt for your idea ... beats the hell of my code some typo thou $searchstring = "pattern1|pattern2|pattern3" if _PatternFound($line, $pattern) then ; do whatever you have to do endif func _PatternFound($line,$pattern) local $stringarray = StringSplit($line, "|") local $counter for $counter = 1 to $stringarray[0] if StringInStr($line,$stringarray[$counter]) then return 1 next return 0 endfunc $pattern should be $searchstring speed improve greatly with _filereadtoarray thanks again ... i think Link to comment Share on other sites More sharing options...
Skruge Posted October 19, 2005 Share Posted October 19, 2005 (edited) Try this: #include <Array.au3> #include <File.au3> opt("MustDeclareVars", 1) Dim $ArraySourceStrings, $ArrayRemoveStrings, $txtValues, $StringsFile, $SourceFile ; File containing strings to remove. (One per line) $StringsFile = "RemoveList.txt" ; Source File $SourceFile = "list.txt" ; Read Strings File _FileReadToArray($StringsFile, $ArrayRemoveStrings) $txtValues = _ArrayToString($ArrayRemoveStrings, "|", 1) ; Prep Strings for RegExp ; Duplicate this line for every character that must be escaped. (Such as Periods) $txtValues = StringReplace($txtValues, ".", "\.") ; Read Source File and Build Results _FileReadToArray($SourceFile, $ArraySourceStrings) For $x = 1 To $ArraySourceStrings[0] If Not StringRegExp($ArraySourceStrings[$x], $txtValues) Then FileWriteLine("_" & $SourceFile, $ArraySourceStrings[$x]) Next ; Done SoundPlay("C:\WINDOWS\Media\ding.wav") MsgBox(0, "", "Done") Edit: Kurt, you beat me to the post with the RegExp idea. Do you know which other characters need to be escaped (besides periods)? Edited October 19, 2005 by Skruge [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
/dev/null Posted October 19, 2005 Share Posted October 19, 2005 (edited) Edit: Kurt, you beat me to the post with the RegExp idea. Do you know which other characters need to be escaped (besides periods)?virtually everything that could have a meaning to RegExp: .,+,*,?, etc... See help file of StringRegExp().CheersKurt Edited October 19, 2005 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
/dev/null Posted October 19, 2005 Share Posted October 19, 2005 thanks kurt for your idea ... beats the hell of my code some typo thousee EDIT: in my first post. Fixed some errors in code.CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * 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