mIRC Home    About    Download    Register    News    Help

Print Thread
T
Teksura
Teksura
T
I've been using my bot to sort various bits of data into a much more pleasing to look at format that is less of a pain for me to use.


I have most of the scripts written, but, I've hit a wall. The final script that is suppose to take all of the data and sort it before presenting it to me keeps making my bot freeze up.
This is my existing rough draft of the script that keeps breaking
Code:
on *:TEXT:!sort:#OuterHeaven: {
  write -c RaidStats.txt
  var %count 1
  while ($lines(wardbreak.txt) != 0) {
    if ($read(wardbreak.txt, w, $chr(32) $+ %count) != $null) {
      write -il1 RaidStats.txt $read(wardbreak.txt, w, $chr(32) $+ %count)
      write -dl $+ $readn wardbreak.txt
    }
    else {
      inc %count
    }
  }
  run C:\Program Files\MIRCTekBot\RaidStats.txt
}


The data in the file wardbreak.txt as well as the other files I will be doing the same thing with are stored in a format like this:

Code:
[b][url=http://www.nexuswar.com/factions/view.do?factionID=1940]Clothed with Authority[/url][/b] 2
[b][url=http://www.nexuswar.com/factions/view.do?factionID=3260]The Grinning Souls[/url][/b] 1
[b][url=http://www.nexuswar.com/factions/view.do?factionID=30]Acta Sanctorum[/url][/b] 1
[b][url=http://www.nexuswar.com/factions/view.do?factionID=3032]John Brown's Raiding Party[/url][/b] 1
[b][url=http://www.nexuswar.com/factions/view.do?factionID=1604]Zpies[/url][/b] 2
[b][url=http://www.nexuswar.com/factions/view.do?factionID=11]Nordic Avengers[/url][/b] 1
[b][url=http://www.nexuswar.com/factions/view.do?factionID=1652]Forsaken[/url][/b] 4
[b][url=http://www.nexuswar.com/factions/view.do?factionID=36]Magi Anonymous[/url][/b] 1


What I'm trying to do is sort them by the number found at the end of each line - highest numbers at the top - when copying them into another file. My overall goal, as you can most likely guess, is to generate a sorted list I can copy/paste onto a forum.


Never had to go looking for help before, so, I apologize if I am lacking any information that I should have included.

Last edited by Teksura; 24/09/08 08:33 AM.
Joined: Aug 2004
Posts: 7,168
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,168
For sorting, there is little (if anything) better than /filter

T
Teksura
Teksura
T
Originally Posted By: RusselB
For sorting, there is little (if anything) better than /filter


Having problems figuring out how to work that

Joined: Jul 2006
Posts: 4,060
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,060
There is a little problem using /filter here.
His file his like this :

Text number
Text1 number1

But in his exemple, some part of "text" contain a space, so we don't know how many space there is for all line

if his text file was like this :

number text
number1 text1

/filter -tue 1 32 will do the job...

A possible solution could be to use another /filter to change the file and put the number before the text, then use the /filter -t.
Or maybe it's possible for the OP to change directly how he wrote the file.




#mircscripting @ irc.swiftirc.net == the best mIRC help channel
T
Teksura
Teksura
T
Hmm, moving the number to the beginning of the line sounds reasonable. I hope that doesn't break my existing stuff...



Yeeeah. That broke the existing stuff. Tried something similar though. When recording the data to its file I used $replace to swap out all spaces with an ASCII character $chr(31) that I will never see among the data I am working with. (As it turns out, $chr(31) is the underline text character, but, it does the job).

So, the number I'm sorting by should now remain as second "word" in each line. I just have to make sure to run another $replace to swap the $chr(31) back to $chr(32)


Lets see how this works now...



Huzzah!


Thanks for all the help with the /filters

Last edited by Teksura; 24/09/08 09:41 PM.
Joined: Aug 2004
Posts: 7,168
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,168
I thought I had read that you could use something like
Code:
/filter -tue -1 32
and it would go from the end of the line. Unfortunately I've been unable to find the reference.

The OP might want to try this, as it would mean that the format of the information in the file wouldn't have to change.

Sorry to post this so late after the OP found a way by changing the format, but I just got home from work.

Joined: Jul 2006
Posts: 4,060
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,060
Originally Posted By: RusselB
I thought I had read that you could use something like
Code:

/filter -tue -1 32

and it would go from the end of the line. Unfortunately I've been unable to find the reference.
I've already tried, it does not work, but it makes a very good suggestion.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Sep 2005
Posts: 2,630
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,630
Starting file:

Code:
[b][url=http://www.nexuswar.com/factions/view.do?factionID=1940]Clothed with Authority[/url][/b] 2
[b][url=http://www.nexuswar.com/factions/view.do?factionID=3260]The Grinning Souls[/url][/b] 1
[b][url=http://www.nexuswar.com/factions/view.do?factionID=30]Acta Sanctorum[/url][/b] 1
[b][url=http://www.nexuswar.com/factions/view.do?factionID=3032]John Brown's Raiding Party[/url][/b] 1
[b][url=http://www.nexuswar.com/factions/view.do?factionID=1604]Zpies[/url][/b] 2
[b][url=http://www.nexuswar.com/factions/view.do?factionID=11]Nordic Avengers[/url][/b] 1
[b][url=http://www.nexuswar.com/factions/view.do?factionID=1652]Forsaken[/url][/b] 4
[b][url=http://www.nexuswar.com/factions/view.do?factionID=36]Magi Anonymous[/url][/b] 1


Ending file (after calling /sortdata scripts\x.txt):

Code:
[b][url=http://www.nexuswar.com/factions/view.do?factionID=3260]The Grinning Souls[/url][/b] 1
[b][url=http://www.nexuswar.com/factions/view.do?factionID=30]Acta Sanctorum[/url][/b] 1
[b][url=http://www.nexuswar.com/factions/view.do?factionID=3032]John Brown's Raiding Party[/url][/b] 1
[b][url=http://www.nexuswar.com/factions/view.do?factionID=11]Nordic Avengers[/url][/b] 1
[b][url=http://www.nexuswar.com/factions/view.do?factionID=36]Magi Anonymous[/url][/b] 1
[b][url=http://www.nexuswar.com/factions/view.do?factionID=1940]Clothed with Authority[/url][/b] 2
[b][url=http://www.nexuswar.com/factions/view.do?factionID=1604]Zpies[/url][/b] 2
[b][url=http://www.nexuswar.com/factions/view.do?factionID=1652]Forsaken[/url][/b] 4


Code:

Code:
alias sortdata filter -cfftu 5 93 $qt($1-) $qt($1-)


Usage: /sortdata <file>

Hope this helps.


Link Copied to Clipboard