Jump to content

Script remove all chars and numbers higher then 2 from a block of 5


 Share

Recommended Posts

Hi Everyone

I made a Script which removes all numbers or chars higher then 2 (3 and more) from a block of 5.

Now there is the Problem. The Script is slow. Sooo slow in fact that it takes ever to run.

I am not a programmer and i happy that it runs and works.

Does anyone know how this Script can be made faster (Yes, there is a sleep in it which makes it slower but i think this is not the big Problem)?

Many Thanks

Regards

Alitai

Quote

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

local $aFile
_FileReadToArray(@ScriptDir &"\more.txt", $aFile)
$sFileName2 = @ScriptDir &"\less.txt"
$hFilehandle2 = FileOpen($sFileName2, $FO_OVERWRITE)
Local $sOriginal
Local $i
$str = 0

While ($str <> 3000000)
$str += 1
$sOriginal = $aFile[$str]
While 1
   Sleep(5)
$si = 0
    $sOne = StringMid($sOriginal, $i+1, 1)
    $sTwo = StringMid($sOriginal, $i+2, 1)
    $sThree = StringMid($sOriginal, $i+3, 1)
    $sFour = StringMid($sOriginal, $i+4, 1)
    $sFive = StringMid($sOriginal, $i+5, 1)
    If $sOne = $sTwo Then
       If $sTwo = $sThree Then
        ExitLoop
       EndIf
    Else
        ;Nothing
    EndIf

    If $sTwo = $sThree Then
       If $sThree = $sFour Then
        ExitLoop
       EndIf
    Else
        ;Nothing
    EndIf

    If $sThree = $sFour Then
       If $sFour = $sFive Then
        ExitLoop
       EndIf
    Else
        ;Nothing
     EndIf

    If $sOne = $sTwo Then
       If $sTwo = $sFour Then
        ExitLoop
       EndIf
    Else
        ;Nothing
     EndIf

    If $sTwo = $sThree Then
       If $sThree = $sFive Then
        ExitLoop
       EndIf
    Else
        ;Nothing
     EndIf

    If $sOne = $sThree Then
       If $sThree = $sFour Then
        ExitLoop
       EndIf
    Else
        ;Nothing
     EndIf

    If $sTwo = $sFour Then
       If $sFour = $sFive Then
        ExitLoop
       EndIf
    Else
        ;Nothing
     EndIf

    If $sOne = $sThree Then
       If $sThree = $sFive Then
        ExitLoop
       EndIf
    Else
        ;Nothing
     EndIf

    If $sOne = $sTwo Then
       If $sTwo = $sFive Then
        ExitLoop
       EndIf
    Else
        ;Nothing
     EndIf

    If $sOne = $sFour Then
       If $sFour = $sFive Then
        ExitLoop
       EndIf
    Else
        FileWrite($hFilehandle2, $sOriginal & @CRLF)
        ExitLoop
     EndIf
    FileWrite($hFilehandle2, $sOriginal & @CRLF)
    ExitLoop
WEnd
WEnd

 

Link to comment
Share on other sites

Your request is hard to understand.

As FrancescoDiMuro just said, post a sample of input file and the expected output, along with a clear reason for removing unwanted lines.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

1 minute ago, FrancescoDiMuro said:

@Alitai

Could you please post an example of the file you are reading? :)

Wow, thanks for your answer first.

Yes, sure:

Quote

9999V
9999B
9999N
9999M
99992
99993
99994
99995
99996
99997
99998
99999
QQW4N
QQW4M
QQW42
QQW43
QQW44
QQW45
QQW46
QQW47
QQW48
QVRNG
QVRNF
QVRND
QVRNY
QVRNX
QVRNC
QVRNV
QVRNB
QVRNN
QVRNM
QVRN2
YDRDK
YDRDJ
YDRDH
YDRDG
YDRDF
YDRDD
YDRDY
YDRDX
YDRDC
YDRDV
YDRDB
YDRDN
YDRDM
YDRD2
YDRD3
YDRD4
YDRD5
YDRD6
YDRD7
YDRD8
YDRD9
YDRYQ
YDRYW
QWQQQ
QWQQW
QWQQR
QWQQT
QWQQP
QWQQK
QWQQJ
QWQQH
QWQQG
QWQQF
QWQQD
QWQQY
QWQQX
QWQQC
QWQQV
QWQQB
QWQQN
QWQQM
QWQQ2
QWQQ3
QWQQ4
QWQQ5
QWQQ6
QWQQ7
QWQQ8
QWQQ9
QWQWQ
QWQWW
QWQWR
QWQWT
QWQWP
QWQWK
QWQWJ
QWQWH
QWQWG

 

Link to comment
Share on other sites

And with this input, what output do you expect?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

3 minutes ago, jchd said:

And with this input, what output do you expect?

It removes all lines which have 3 or more of the same chars or numbers in it.

Output:

Quote

QQW4N
QQW4M
QQW42
QQW43
QQW44
QQW45
QQW46
QQW47
QQW48
QVRNG
QVRNF
QVRND
QVRNY
QVRNX
QVRNC
QVRNV
QVRNB
QVRNN
QVRNM
QVRN2
YDRDK
YDRDJ
YDRDH
YDRDG
YDRDF
YDRDY
YDRDX
YDRDC
YDRDV
YDRDB
YDRDN
YDRDM
YDRD2
YDRD3
YDRD4
YDRD5
YDRD6
YDRD7
YDRD8
YDRD9
YDRYQ
YDRYW

 

Link to comment
Share on other sites

#include <File.au3>

local $aFile, $aTxt
_FileReadToArray("more.txt", $aFile)
_ArrayDisplay ($aFile)
For $i = 1 to $aFile[0]
  $aTxt = StringSplit ($aFile[$i], "", $STR_NOCOUNT)
  $aTxt = _ArrayUnique ($aTxt)
  If $aTxt[0] <= 3 Then ContinueLoop
  ConsoleWrite ($aFile[$i] & @CRLF)
Next

Try this 

Edited by Nine
Link to comment
Share on other sites

Also this:

Local $aFile = FileReadToArray(@ScriptDir & "\more.txt")
Local $hFilehandle = FileOpen(@ScriptDir & "\less.txt", $FO_OVERWRITE)

For $s In $aFile
    If Not StringRegExp($s, "^(.)\g-1\g-1..|^(.)\g-1.\g-1.|^(.)\g-1..\g-1|^(.).\g-1\g-1.|^(.).\g-1.\g-1|^(.)..\g-1\g-1|^.(.)\g-1\g-1.|^.(.)\g-1.\g-1|^.(.).\g-1\g-1|^..(.)\g-1\g-1") Then FileWriteLine($hFilehandle, $s)
Next
FileClose($hFilehandle)

 

Edited by jchd
Fixed idiotic copy

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

5 minutes ago, Nine said:
#include <File.au3>

local $aFile, $aTxt
_FileReadToArray("more.txt", $aFile)
_ArrayDisplay ($aFile)
For $i = 1 to $aFile[0]
  $aTxt = StringSplit ($aFile[$i], "", $STR_NOCOUNT)
  $aTxt = _ArrayUnique ($aTxt)
  If $aTxt[0] <= 2 Then ContinueLoop
  ConsoleWrite ($aFile[$i] & @CRLF)
Next

Try this 

You missed a few.

for example: QWQQN

This must also be removed.

There are 10 combinations to test.

thanks for this short script this is crazy crazycrazy... :) i would never be able to made it so short..

Regards

Alitai

Link to comment
Share on other sites

Did mine work for you?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Link to comment
Share on other sites

7 minutes ago, Nine said:

replace 2 by 3, it is corrected in my script, typo....

Your script takes out 2 doubles also.

Like: YDRDY

But thats okay. Because that's what i doing in the 2nd run with a other script at the Moment.

Can you confirm?

@jchdThe other Script i will test in a sec...

Thanks

Regards

Alitai

Link to comment
Share on other sites

I fixed it right now

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

The fixed version should work.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

46 minutes ago, Alitai said:

Can you confirm?

Yes you are right.  It is removing 2 doubles.  Then try using this to solve the issue :

#include <File.au3>
local $aFile, $aTxt, $sSort
_FileReadToArray("more.txt", $aFile)
For $i = 1 to $aFile[0]
  $aTxt = StringSplit ($aFile[$i], "", $STR_NOCOUNT)
  _ArraySort ($aTxt)
  $sSort = _ArrayToString ($aTxt, "")
  If StringRegExp ($sSort, "(.)\g1\g1") Then ContinueLoop
  ConsoleWrite ($aFile[$i] & @CRLF)
Next

 

Link to comment
Share on other sites

14 minutes ago, jchd said:

The fixed version should work.

Yes, now it works. Thanks so much.

@Nine Ahh cool! Thank you too.

I have now to Test everything with bigger lists.

Thank you all so much for the help.

Crazy :hyper:

Thanks

Regards

Alitai

Link to comment
Share on other sites

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...