mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline OP
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
what i want is to try and verify string 1 which contains 20 bytes with string 2 that contains 6 bytes and string 1 contains various multiple lines in the text file while the string 2 contains it only 1 time only. I would like the matches result to be returned as total and tell me which is the result numbers that were found matching. all Echo'd to me.

Here is a breakdown of what Im trying to do



Im trying to verify data (Numerical) in the first section which is always static which are 20 bytes static but always different values.

Ex:. 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20

Aka 20 bytes

These numbers are random, Never the same however its always in order and up to 99.

What im trying to do is verify the string data to see if and how many matches there is in the second string data which is always 6 bytes.

Ex:. 01 02 03 04 05 06

Aka 6 bytes

in the example I would find that String 2 contains 6 matching results from string 1 because 01 02 03 04 05 06 is present.

Now Here's a more tricky part. String 1 is writting to text file on various lines while string 2 changes once a week only 1 time on another text file. Therefore I need to script to be able to compare the results in a while or some kind of loop. so the end result appears as

(Value found in text file of string 1) Found 3 matches from (String 2)
(Value found in text file of string 2) Found 0 matches from (String 2)

etc..

And if possible to also include the result numbers that were found is 03 04 05 then to tell me.

Sorry for the long post I don't even know if I wrote it properly Im rusty @ scripting i just got back into it after coming back from vacation and I can't figure this out.

I've tried to write the data in text files both of them and read it through in a loop and get the data one by one in a IF statement then increment a variable if one result is found however that doesn't work out.

Ex;>

Code:
 
alias cycnum { 
  var %x = 1
  while (%x <= $lines(let.txt)) {
    if ($gettok($read(numbs.txt,1),1,32) isin $read(let.txt,%x)) { %sixf = 1 }
    if ($gettok($read(numbs.txt,1),2,32) isin $read(let.txt,%x)) { inc %sixf }
    if ($gettok($read(numbs.txt,1),3,32) isin $read(let.txt,%x)) { inc %sixf }
    if ($gettok($read(numbs.txt,1),4,32) isin $read(let.txt,%x)) { inc %sixf }
    if ($gettok($read(numbs.txt,1),5,32) isin $read(let.txt,%x)) { inc %sixf }
    if ($gettok($read(numbs.txt,1),6,32) isin $read(let.txt,%x)) { inc %sixf }
    .timer 1 2 /echo -a 7,1Found --- %sixf --- Matches in --- $read(let.txt,%x) 
    unset %sixf
    inc %x
  }
}



Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I'm going to have to do some more research, unless someone else can do this first, but I've got a feeling that a regex statement would be best for this. My knowledge of regex is limited, so I want to verify before giving you a code, but I won't be doing that until later (as it's 3:30 am).

BTW: I hope you had a nice vacation, and it's good to see you back.

Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline OP
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Thanks for the WB I was thinking of a regex as well its weird how one looses knowledge of scripting then regains it once a few scripts are written.

Im sure I would of solved this by now imm still confused.


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Joined: Jan 2007
Posts: 259
K
Fjord artisan
Offline
Fjord artisan
K
Joined: Jan 2007
Posts: 259
I'd say that regex is the best way to go, and you should also use $read(x.txt,t,line) when dealing with numbers.

It'd be great if you could confirm if this is the way you want to search:
let.txt has the numbers to be matched, and numbs.txt has the numbers on line 1 that the numbers from let.txt are to be found in.


Those who can, cannot. Those who cannot, can.
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
The numbers you have shown are not bytes. Assuming the data looks exactly how you have shown it, then one of these should work for counting the numbers for you.

Code:
alias numcount {
  var %haystack = 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
  var %needle = 04 05 06 07 08 09

  %needle = /( $+ $regsubex(%needle,/ /g,$chr(124)) $+ )/g
  var %count = $regex(%haystack,%needle)

  echo -a %count 
}

alias numcountret {
  var %haystack = 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
  var %needle = 04 05 06 07 08 09
  var %matches, %count = 0

  var %c = 0, %cc = $numtok(%needle,32)
  while (%c < %cc) {
    inc %c
    if ($count(%haystack,$gettok(%needle,%c,32))) {
      %matches = $addtok(%matches,$gettok(%needle,%c,32),32)
      inc %count $v1
    }
  }

  echo -a %count : %matches
}


The first alias calculates the count only. The second alias calculates the count and retains the matches. You will have to integrate those aliases into your code if you want to read from text files, etc.

-genius_at_work

Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline OP
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Well this is the long method code for my request that I did and results the proper result considering string 2 is being verified one by one in the if statements to the string 1

Syntax use: Inject 6 bytes in text file name it nume.txt stored in root dir, Inject 20 Bytes in text file name it let.txt stored in root dir, execute command /cycnum

Code:
 
alias cycnum { 
  %sixf = 0
  var %x = 1
  while (%x <= $lines(let.txt)) {
    if ($wildtok($read(let.txt,%x),$gettok($read(nume.txt),1,32),0,32) == 1) { 
      inc %sixf 
      if (%rez) { %rez = %rez $wildtok($read(let.txt,%x),$gettok($read(nume.txt),1,32),1,32) }
      else { %rez = $wildtok($read(let.txt,%x),$gettok($read(nume.txt),1,32),1,32) }
    }
    if ($wildtok($read(let.txt,%x),$gettok($read(nume.txt),2,32),0,32) == 1) { 
      inc %sixf 
      if (%rez) { %rez = %rez $wildtok($read(let.txt,%x),$gettok($read(nume.txt),2,32),1,32) }
      else { %rez = $wildtok($read(let.txt,%x),$gettok($read(nume.txt),2,32),1,32) }
    }
    if ($wildtok($read(let.txt,%x),$gettok($read(nume.txt),3,32),0,32) == 1) { 
      inc %sixf 
      if (%rez) { %rez = %rez $wildtok($read(let.txt,%x),$gettok($read(nume.txt),3,32),1,32) }
      else { %rez = $wildtok($read(let.txt,%x),$gettok($read(nume.txt),3,32),1,32) }
    }
    if ($wildtok($read(let.txt,%x),$gettok($read(nume.txt),4,32),0,32) == 1) { 
      inc %sixf 
      if (%rez) { %rez = %rez $wildtok($read(let.txt,%x),$gettok($read(nume.txt),4,32),1,32) }
      else { %rez = $wildtok($read(let.txt,%x),$gettok($read(nume.txt),4,32),1,32) }    
    }
    if ($wildtok($read(let.txt,%x),$gettok($read(nume.txt),5,32),0,32) == 1) {
      inc %sixf 
      if (%rez) { %rez = %rez $wildtok($read(let.txt,%x),$gettok($read(nume.txt),5,32),1,32) }
      else { %rez = $wildtok($read(let.txt,%x),$gettok($read(nume.txt),5,32),1,32) }
    }
    if ($wildtok($read(let.txt,%x),$gettok($read(nume.txt),6,32),0,32) == 1) { 
      inc %sixf 
      if (%rez) { %rez = %rez $wildtok($read(let.txt,%x),$gettok($read(nume.txt),6,32),1,32) }
      else { %rez = $wildtok($read(let.txt,%x),$gettok($read(nume.txt),6,32),1,32) }
    }
    /echo -a 7,1Found --- %sixf --- Matches in --- $read(let.txt,%x) --- Result Match:  $+ %rez
    unset %sixf
    unset %rez
    inc %x
  }
}


Or a Cleaner method like this but I still find the script a bit lenghty and think this could be done another way

Code:
 
alias cycCall { return $wildtok($read(let.txt,%x),$gettok($read(nume.txt),$1,32),$2,32) }

alias cycnum { 
  %sixf = 0
  %x = 1
  while (%x <= $lines(let.txt)) {
    if ($cycCall(1,0) == 1) { 
      inc %sixf 
      if (%rez) { %rez = %rez $cycCall(1,1) }
      else { %rez = $cycCall(1,1) }
    }
    if ($cycCall(2,0) == 1) { 
      inc %sixf 
      if (%rez) { %rez = %rez $cycCall(2,1) }
      else { %rez = $cycCall(2,1) }
    }
    if ($cycCall(3,0) == 1) { 
      inc %sixf 
      if (%rez) { %rez = %rez $cycCall(3,1) }
      else { %rez = $cycCall(3,1) }
    }
    if ($cycCall(4,0) == 1) { 
      inc %sixf 
      if (%rez) { %rez = %rez $cycCall(4,1) }
      else { %rez = $cycCall(4,1) }    
    }
    if ($cycCall(5,0) == 1) {
      inc %sixf 
      if (%rez) { %rez = %rez $cycCall(5,1) }
      else { %rez = $cycCall(5,1) }
    }
    if ($cycCall(6,0) == 1) { 
      inc %sixf 
      if (%rez) { %rez = %rez $cycCall(6,1) }
      else { %rez = $cycCall(6,1) }
    }
    /echo -a 7,1Found --- %sixf --- Matches in --- $read(let.txt,%x) --- Result Match:  $+ %rez
    unset %sixf
    unset %rez
    inc %x
  }
}


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline OP
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Originally Posted By: genius_at_work
The numbers you have shown are not bytes. Assuming the data looks exactly how you have shown it, then one of these should work for counting the numbers for you.

Code:
alias numcount {
  var %haystack = 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
  var %needle = 04 05 06 07 08 09

  %needle = /( $+ $regsubex(%needle,/ /g,$chr(124)) $+ )/g
  var %count = $regex(%haystack,%needle)

  echo -a %count 
}

alias numcountret {
  var %haystack = 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
  var %needle = 04 05 06 07 08 09
  var %matches, %count = 0

  var %c = 0, %cc = $numtok(%needle,32)
  while (%c < %cc) {
    inc %c
    if ($count(%haystack,$gettok(%needle,%c,32))) {
      %matches = $addtok(%matches,$gettok(%needle,%c,32),32)
      inc %count $v1
    }
  }

  echo -a %count : %matches
}


The first alias calculates the count only. The second alias calculates the count and retains the matches. You will have to integrate those aliases into your code if you want to read from text files, etc.

-genius_at_work


Aww thanks man, Ya I know they are not bytes im just showing an example of the format.


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }

Link Copied to Clipboard