Jump to content
UBot Underground

Sort a list of numbers


Recommended Posts

Hi all,

 

I have a list of numbers that I need to sort. When I use "$sort list" all the numbers are sorted by the first digit but not the whole number. Any idea how can I do that.

 

Example of list:

 

1000

1100

100

1

 

What a need:

 

1

100

1000

1100

 

Thanks!

Link to post
Share on other sites

set(#temp, "100
5000
1100
1000
10", "Global")
clear list(%test)
add list to list(%test, $list from text(#temp, $new line), "Delete", "Global")
clear list(%clean)
add list to list(%clean, $sort list(%test, "Ascending"), "Delete", "Global")
clear list(%test)

 

seems to be working.

http://screencast.com/t/PIVU4alT63Sx

Link to post
Share on other sites

It's probably because UBot works with strings, not numbers. There is probably a type casting of strings every time Ubot does any mathematical stuff with numbers.

 

You could probably try to add a proper amount of zeros in the beginning of each number, except for the biggest number(s). Ok, it's not very beautiful, but it will probably work.

Link to post
Share on other sites

Hi,

 

If you were to save the list to a text file.

 

You could then run a Ubot shell cmd.exe /C sort input-file.txt /O sorted-file.txt

Window Command Prompt sort /? for help.

 

Then read the sorted text file back in to a list variable for further processing.

 

Kevin

Link to post
Share on other sites
  • 1 month later...

Hey Willy,

 

Thanks for trying to help me out.

 

I will try this in a sec, but do you know if it will keep the order.

 

For example my list is 1289,website.com - 1238,website.com - so on and so forth.

 

Will this keep the right websites associated with the right numbers?

 

Thanks,

Justin

Link to post
Share on other sites

Hey Willy,

 

Not working for numbers outside of their comma...

 

For instance:

1,000,000

1,321

10,000,321

100,011

20,032

31,209,290

100

40,021

500,930

 

It will not sort this list correctly. Unless I am missing something :blink:

Link to post
Share on other sites

That will work for just the numbers.

 

But, after my numbers I have domains. And some of them are short and the other ones are long. So length does not work in my case.

 

Ex:

1,000,000,acme.com

1,321,acmewebsite.com

10,000,321,a.com

100,011,xyz.com

20,032,acme.com

31,209,290,acme.com

100,acmesbiggestwebsite.com

40,021,acmesotherbiggestwebsite.com

500,930,ubot.com

 

Gives me the following when using length:

100,011,xyz.com

20,032,acme.com

10,000,321,a.com

500,930,ubot.com

1,000,000,acme.com

31,209,290,acme.com

1,321,acmewebsite.com

100,acmesbiggestwebsite.com

40,021,acmesotherbiggestwebsite.com

 

So this is quite a dilema. Doesn't seem to be a fix for this...

 

Justin

Link to post
Share on other sites

I think this is the exact issue at hand and shows means how it can be fixed by means of a update to ubot functionality.

 

 

http://blogs.technet.com/b/heyscriptingguy/archive/2008/02/12/how-can-i-use-windows-powershell-to-sort-a-csv-file.aspx

  • Like 2
Link to post
Share on other sites

This works:

var outs = Array();
outs.length = 999999999;
var source ="31209290,acme.com\n100,acmesbiggestwebsite.com\n40021,acmesotherbiggestwebsite.com";
var list = source.split("\n");
for (i in list) {
parts = list[i].split(",");
outs[parts[0]] = list[i];
}
var sortedlist = "";
for (j in outs) {if (outs[j]) sortedlist = sortedlist +outs[j] +"\n";}
return sortedlist;

Link to post
Share on other sites

What exactly you want to do and how this numbers and domains are gathered?

 

You can accomplish things in different ways with ubot.

 

For example you could have the numbers sorted first and then replace the number for number with the domain at the end.

I am scraping a large lists of sites to get their alexa rank.

 

It outputs the file as a semi colon seperated .txt file i.e. - Alexa Rank;Website.

 

I would like to be able to save it with the highest rated ranking on top and go on from there.

 

I believe I can achieve this in excel, but that kind of defeats the whole purpose of "automating" this task.

 

Thanks for all the suggestions so far...

 

Would be nice to get this working. :)

Link to post
Share on other sites

This works:

var outs = Array();
outs.length = 999999999;
var source ="31209290,acme.com\n100,acmesbiggestwebsite.com\n40021,acmesotherbiggestwebsite.com";
var list = source.split("\n");
for (i in list) {
parts = list[i].split(",");
outs[parts[0]] = list[i];
}
var sortedlist = "";
for (j in outs) {if (outs[j]) sortedlist = sortedlist +outs[j] +"\n";}
return sortedlist;

How exactly do I use this?

 

Run it as Javascript?

 

How do I use it with a list? How do I output it back to a list?

 

Thanks,

Justin

Link to post
Share on other sites

How exactly do I use this?

 

Run it as Javascript?

 

How do I use it with a list? How do I output it back to a list?

 

Thanks,

Justin

 

I'd do it more or less like:


set(#input, "132,test1\n", "Global")
set(#input, "{#input}8931,test2\n", "Global")
set(#input, "{#input}1322221,test3\n", "Global")
set(#input, "{#input}5499,test4\n", "Global")

set(#sorted, $eval("
var outs = Array();
outs.length = 999999999;
var source =\"{#input}\";
var list = source.split(\"\\n\");
for (i in list) \{
parts = list[i].split(\",\");
outs[parts[0]] = list[i];
\}
var sortedlist = \"\";
for (j in outs) \{if (outs[j]) sortedlist = sortedlist +outs[j] +\"\\n\";\}
sortedlist;
"), "Global")
alert(#sorted)

 

Of course the set for #input would be in your loop and probably be more like set(#input, "{#input}{#rank},{#domain}\n", "Global") and it's probably a better idea to save #sorted instead of alert but that's probably the easiest way to skin the cat.

  • Like 2
Link to post
Share on other sites

I'd do it more or less like:


set(#input, "132,test1\n", "Global")
set(#input, "{#input}8931,test2\n", "Global")
set(#input, "{#input}1322221,test3\n", "Global")
set(#input, "{#input}5499,test4\n", "Global")

set(#sorted, $eval("
var outs = Array();
outs.length = 999999999;
var source =\"{#input}\";
var list = source.split(\"\\n\");
for (i in list) \{
parts = list[i].split(\",\");
outs[parts[0]] = list[i];
\}
var sortedlist = \"\";
for (j in outs) \{if (outs[j]) sortedlist = sortedlist +outs[j] +\"\\n\";\}
sortedlist;
"), "Global")
alert(#sorted)

 

Of course the set for #input would be in your loop and probably be more like set(#input, "{#input}{#rank},{#domain}\n", "Global") and it's probably a better idea to save #sorted instead of alert but that's probably the easiest way to skin the cat.

 

I'm guessing this is regex?... Haven't learned that yet.

 

Gonna have to sleep on that one.

 

I'm sure it will click in the morning.

 

Still open for easier solutions though ;)

 

Still looking for easier ways to skin the cat.

 

Keep in mind I am trying to sort the list After it is created, with a semi colon delimiter.

 

I guess I just need to know if this is possible within Ubot, or maybe thejake could possibly dumb it down for me? Feel free to PM me or share it here.

 

Justin

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...