Page 1 of 1
reverse (retrograde) sorting under F9
Posted: Fri Jul 20, 2007 12:20 pm
by Arnoud van den Eerenbeemt
As a Dutch lexicographer and developer of medical dictionaries and a medical spellchecker, I use TextPad for coding and sorting lexical data. I would be greatly helped with an option under F9 for sorting lines in reverse order (retrograde). Is this an option that will be appreciated by others too and could it possibly be included in a future version? For this purpose I now have to resort to WordSmith, a linguistic tools suite that requires a lot of data preprocessing before obtaining the desired result.
Regards,
Arnoud
Posted: Fri Jul 20, 2007 4:15 pm
by Bob Hansen
Does Tools/Sort/Descending not work?
reverse (retrograde) sorting under F9
Posted: Sat Jul 21, 2007 8:25 am
by Arnoud van den Eerenbeemt
Hi Bob,
Thanks for suggesting. No, that is not what I mean. Consider:
- ascending sorting: Bob | Dick | Harry | John | Paul
- descending sorting: Paul | John | Harry | Dick | Bob
- sorted reversely, you would get: Bob | Dick | Paul | John | Harry, based on the names' last letters, here resp. b, k, l, n, y.
Regards,
Arnoud
Posted: Sat Jul 21, 2007 9:25 am
by ben_josephs
In Perl:
Code: Select all
print sort { ( reverse $a ) cmp ( reverse $b ) } <> ;
although that won't scale well for very large files.
Posted: Sun Jul 22, 2007 8:43 pm
by Bob Hansen
Thanks for sample of retrograde.
Will whole line be in retrograde or each word?
Posted: Sun Jul 22, 2007 10:58 pm
by ben_josephs
Ah, I see.
To sort the
|-separated items on each line you might need something like:
Code: Select all
for my $line ( <> )
{
chomp $line ;
$line =~ s/ +$// ;
my @elems = split ' *\| *', $line ;
my @sortedElems = sort { ( reverse $a ) cmp ( reverse $b ) } @elems ;
my $sortedLine = join ' | ', @sortedElems ;
print "$sortedLine\n" ;
}
No problems there with scalability.
Posted: Mon Jul 23, 2007 8:18 am
by Arnoud van den Eerenbeemt
Gentlemen, thanks for your attempt to help me out. Alas, I am no Perl programmer, so this code is abacadabra to me. Will this input enable/motivate Helios to include reverse sorting in a future update of TextPad?
Sincerely, Arnoud
Posted: Mon Jul 23, 2007 11:57 am
by ben_josephs
I doubt it; this is a very special-purpose requirement. If every such special need were catered for directly, TextPad's code and user interface would bloat hugely.
If your work involves much text handling you will find it extremely useful to have at your disposal a general-purpose language with powerful text handling facilities, such as Perl, Python, Ruby, Tcl, or what you will. Otherwise you will always be restricted to whatever was thought of or thought to be important by the author of the limited-functionality tools you use.
Unfortunately, TextPad does not support the writing of scripts in any language. Requirements like yours are a good argument for the inclusion of this functionality.
BTW, why do you want to order words (or lines) in this way?
Posted: Tue Nov 15, 2011 2:44 am
by varav
(Yes, I realize this is a VERY old thread)
given this list of names:
bob
cindy
mel
barbara
gene
find ------------ ^(.*)(.)$
replace --------- \2 \1\2
take note of the SPACE following the initial "backslash two"
ReplaceAll
the result:
b bob
y cindy
l mel
a barbara
e gene
Next, Tools } Sort produces:
a barbara
b bob
e gene
l mel
y cindy
Then
find ---------- ^.[ ]
replace ---------- leave empty
ReplaceAll
Now we have the "retrograde sorted" list:
barbara
bob
gene
mel
cindy