aa
aa
aa
bb
cc
cc
ee
ee
ee
ee
How do you sort words by number of repetitions?
e.g. from the most common to the single.
ee
ee
ee
ee
aa
aa
aa
cc
cc
bb
Sorting problem.
- Author
- Message
-
Offline
- Posts: 874
- Joined: Sat Jan 16, 2010 2:03 pm
sexy96
Maybe "offtop", but, probably, the easiest way is to use SQL (SQLite for example).
Import text into a database. The database query. Export query results to text file.
1. Import file "qq-1.txt" with non-sorted data.
2. Run query:
3. Save result as "View" with name 'tmpdata'
4. Run query:
5. Save result as txt file (Export to CSV).
P.S. Import txt file have some bug (the last row in file can ignored) so you must add 1 extra empty line in the end of your file before.
Maybe "offtop", but, probably, the easiest way is to use SQL (SQLite for example).
Import text into a database. The database query. Export query results to text file.
1. Import file "qq-1.txt" with non-sorted data.
2. Run query:
Code: Select all
select field1, count(field1) as cnt
from 'qq-1'
group by field1
order by cnt desc4. Run query:
Code: Select all
select tmpdata.field1
from 'qq-1', 'tmpdata'
where tmpdata.field1 = 'qq-1'.field1
order by cnt descP.S. Import txt file have some bug (the last row in file can ignored) so you must add 1 extra empty line in the end of your file before.
-
Offline
- Posts: 1949
- Joined: Sat Mar 06, 2010 7:40 pm
- Location: Poland
sexy96
Use JS script:
Use JS script:
Code: Select all
var oSys = AkelPad.SystemFunction();
var sNL = ["\r\n", "\n", "\r"][AkelPad.GetEditNewLine(0) - 1];
var oCount = {};
var aWord;
var n;
if (AkelPad.GetSelStart() == AkelPad.GetSelEnd())
AkelPad.SetSel(0, -1);
aWord = AkelPad.GetSelText().split("\r");
for (n = 0; n < aWord.length; ++n)
{
if (aWord[n] in oCount)
++oCount[aWord[n]];
else
oCount[aWord[n]] = 1;
}
aWord.sort(function CompareValue(sA, sB)
{
if (oCount[sA] == oCount[sB])
return oSys.Call("Kernel32::lstrcmpW", sA, sB);
return (oCount[sB] - oCount[sA]);
}
);
AkelPad.ReplaceSel(aWord.join(sNL));