mIRC Home    About    Download    Register    News    Help

Print Thread
#148207 01/05/06 06:16 AM
Joined: May 2006
Posts: 7
A
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: May 2006
Posts: 7
I have a text file with 2 columns of numbers. I used /filter to sort it by column 1. The thing is that a lot of the numbers in column 1 are the same. And for those lines that they are, I need to sort those lines by column 2 but still keep column 1 in the correct order. Any help on this would be greatly appreciated.

Here is an example of my file:

7 684
5 286
3 5
3 113
3 1
2 174
2 189
2 187
2 198
2 0
1 78
1 5
1 5
1 5
1 5
1 5
1 32

#148208 01/05/06 06:21 AM
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
How about sorting 2 files individually, for column 1 and column 2 and combining them? Or do I have the wrong idea here?

-Andy

#148209 01/05/06 06:27 AM
Joined: May 2006
Posts: 7
A
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: May 2006
Posts: 7
Im not sure, the result im looking for is turning that list there into this:
7 684
5 286
3 113
3 5
3 1
2 198
2 189
2 187
2 174
2 0
1 78
1 32
1 5
1 5
1 5
1 5
1 5

Basically if the lines have the same number for colum 1, then sort those lines by colum 2. but keep the correct descending order for column 1. If that makes sense...

#148210 01/05/06 06:46 AM
Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
use an @window with the sort switch
/window -s @sort

then load in the values
/loadbuf @sort thetextfile.txt

then save the @window back to the text
/savebuf @sort thetextfile.txt

Code:
alias sortit {
  window -s @sort
  loadbuf @sort tmp
  savebuf @sort tmp
  window -c @sort
  run notepad tmp
}


see if that works for you

#148211 01/05/06 06:52 AM
Joined: May 2006
Posts: 7
A
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: May 2006
Posts: 7
I think that just sorts it in ascending order based on the first character.

#148212 01/05/06 07:04 AM
Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
the first character in each column I believe

#148213 01/05/06 10:51 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
You can use /filter's -a option, to specify a custom sorting alias. In your case, it would look like this:
Code:
alias customsort {
  tokenize 32 $1-
  if ($calc($3 - $1)) return $v1
  return $calc($4 - $2)
}
Then to sort your file, you'd execute this
Code:
/filter -ffca file.txt file.txt customsort


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#148214 01/05/06 10:55 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
example....
/filter -ffca file.txt file.txt filteralias *

&

Code:
alias filteralias {
  if ($gettok($1,1,32) < $gettok($2,1,32)) return  1
  if ($gettok($1,1,32) > $gettok($2,1,32)) return -1
  if ($gettok($1,2,32) < $gettok($2,2,32)) return  1
  if ($gettok($1,2,32) > $gettok($2,2,32)) return -1
}


the -a option sorts by passing to the alias names "filteralias" the two lines being compared at that time, then i compare the first column resulting in +1 or -1 for less or greater than (reverse of < being -1 & > being +1 becuase u wanted descending sort), if there the same i move to the second column doing the same.


** I well say that should the list of numbers be really really big, it might be better to do it other ways such as create a temp window with some type of compound value, sort that and then rebuild a uncompounded resultset, but i think if u got say under 1000 lines this is likely the simplest and cleanest way.

[i]pfffttt querty beat me to posting, that well teach me for writing text at the bottom. :-)
Only thing my alias might have over his is mine well ignore if other values are also on the lines as well, i dont know if there ever would be or not tho.
I assume Querties alias is better than mine if there are not any extra values on the line (column3+ etc) as the shorter the alias the better as its called numerius times for the sorting process

Last edited by DaveC; 01/05/06 10:59 AM.

Link Copied to Clipboard