Horizontal sort ?

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Vongalin
Posts: 2
Joined: Wed Jan 02, 2008 9:00 pm

Horizontal sort ?

Post by Vongalin »

Is there anything that allows you to do horizontal sorting ? For example, I have this snippet from a line of SQL (NOTE : the following is on a single line inside of TextPad)

Code: Select all

(12774, 15569, 16313, 18350, 34082, 18350, 16311, 11920, 9127, 22838, 21866, 25201, 42004, 10347, 12348, 31517, 30227, 30684, 30677, 30685, 29945, 30676, 25107, 43450, 43492, 43755, 43663, 42424, 44368, 43714, 43660, 43662, 42146, 25861, 36795, 30417, 30418, 6119, 6123, 21268, 22108, 22109, 22110, 22111, 22112, 22113, 21338, 21356, 21731, 21368, 21078, 21372, 21465, 21464, 21542, 21541, 21732, 22114, 22115, 22116, 22117, 22118, 22119, 21734, 21735, 30473, 16510, 21654, 28287, 21398, 23059, 23019, 8609, 32094, 27583, 32260, 42010, 23107, 25846, 41560, 41457, 108, 32476, 23949, 23950, 2585, 25170, 2110, 36727, 39303, 43090, 21794, 39401, 33316, 25105, 8596, 32475, 44501, 23053, 27360, 29297, 29279, 21649, 39398, 39400, 20466, 24727, 3440, 38721, 31337, 31377, 31336, 21051, 25172, 28688, 21052, 27879, 27881, 27882, 29294, 29295, 24256, 24279, 24280, 24282, 24285, 24284, 24281, 24288, 24289, 24290, 22969, 33380, 28355, 25106, 43535, 27824, 20514, 6431, 10263, 6606, 14915, 16093, 6844, 24184, 29533, 40359, 40384, 39993, 27251, 18350, 5302, 25148, 31951, 31954, 25182, 30428, 22207, 23159, 27190, 27191, 27201, 28872, 27202, 27184, 23176, 32318, 27517, 31335, 27203, 21391, 21397, 23460, 29190, 25139, 29181, 24653, 32025, 36325, 30431, 25171, 31929, 30882, 32073, 29479, 21653, 20465, 20358, 30446, 21896, 43345, 43347, 43346, 38586, 38998, 38996, 38992, 39163, 38997, 39225, 39377, 39185,5301, 13358, 16092, 11920, 18350, 10400, 34084, 18350, 24948, 23192, 9127, 2916, 4810, 4811, 4644, 4637, 4659, 4660, 4651, 4652, 4675, 4676, 4667, 4668, 4694, 4695, 4687, 4688, 5948, 5944, 4712, 4713, 4705, 4706, 42507, 8298, 32420, 25697, 40154, 40890, 40905, 2598, 2381, 3653, 3652, 27035, 4730, 4723, 3, 1, 50)
and I was trying to come up with a way that I could sort it. Would I have to try the Reformat, sort, then somehow Un-reformat ?
User avatar
Bob Hansen
Posts: 1517
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Quick untested approach:

Replace comma-space with \n to make one value in each row.
Sort the single column
Replace each \n with comma-space.
Hope this was helpful.............good luck,
Bob
ben_josephs
Posts: 2457
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

This would be quite tricky in TextPad, which doesn't support scripts. But you can do it on the Windows command line with something like this Perl one-liner:

Code: Select all

perl -ne "m/(.*\()(.*?)(\))/ ; print $1, ( join ', ', sort { $a <=> $b } split /, ?/, $2 ), $3"
which yields

Code: Select all

(1, 3, 50, 108, 2110, 2381, 2585, 2598, 2916, 3440, 3652, 3653, 4637, 4644, 4651, 4652, 4659, 4660, 4667, 4668, 4675, 4676, 4687, 4688, 4694, 4695, 4705, 4706, 4712, 4713, 4723, 4730, 4810, 4811, 5301, 5302, 5944, 5948, 6119, 6123, 6431, 6606, 6844, 8298, 8596, 8609, 9127, 9127, 10263, 10347, 10400, 11920, 11920, 12348, 12774, 13358, 14915, 15569, 16092, 16093, 16311, 16313, 16510, 18350, 18350, 18350, 18350, 18350, 20358, 20465, 20466, 20514, 21051, 21052, 21078, 21268, 21338, 21356, 21368, 21372, 21391, 21397, 21398, 21464, 21465, 21541, 21542, 21649, 21653, 21654, 21731, 21732, 21734, 21735, 21794, 21866, 21896, 22108, 22109, 22110, 22111, 22112, 22113, 22114, 22115, 22116, 22117, 22118, 22119, 22207, 22838, 22969, 23019, 23053, 23059, 23107, 23159, 23176, 23192, 23460, 23949, 23950, 24184, 24256, 24279, 24280, 24281, 24282, 24284, 24285, 24288, 24289, 24290, 24653, 24727, 24948, 25105, 25106, 25107, 25139, 25148, 25170, 25171, 25172, 25182, 25201, 25697, 25846, 25861, 27035, 27184, 27190, 27191, 27201, 27202, 27203, 27251, 27360, 27517, 27583, 27824, 27879, 27881, 27882, 28287, 28355, 28688, 28872, 29181, 29190, 29279, 29294, 29295, 29297, 29479, 29533, 29945, 30227, 30417, 30418, 30428, 30431, 30446, 30473, 30676, 30677, 30684, 30685, 30882, 31335, 31336, 31337, 31377, 31517, 31929, 31951, 31954, 32025, 32073, 32094, 32260, 32318, 32420, 32475, 32476, 33316, 33380, 34082, 34084, 36325, 36727, 36795, 38586, 38721, 38992, 38996, 38997, 38998, 39163, 39185, 39225, 39303, 39377, 39398, 39400, 39401, 39993, 40154, 40359, 40384, 40890, 40905, 41457, 41560, 42004, 42010, 42146, 42424, 42507, 43090, 43345, 43346, 43347, 43450, 43492, 43535, 43660, 43662, 43663, 43714, 43755, 44368, 44501)
Edit: fixed typo.
Last edited by ben_josephs on Wed Jan 02, 2008 10:49 pm, edited 1 time in total.
Ryck
Posts: 50
Joined: Thu Mar 17, 2005 4:20 am

Post by Ryck »

Bob Hansen wrote:Quick untested approach:

Replace comma-space with \n to make one value in each row.
Sort the single column
Replace each \n with comma-space.
For what it's worth, that was the method I used to sort a snippet of SQL code for someone else. So it does work.

Then I found it was unnecessary if you include the 'ORDER BY' clause in the SQL. For example, if these were PRODUCTIDs, then if you add an 'ORDER BY PRODUCTID' to the SQL statement, then no matter what the order the PRODUCTID elements are listed inside the 'IN()' clause the results will be sorted by PRODUCTID anyway.

Hope this point helps the user who asked the question.

.r.
ben_josephs
Posts: 2457
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Bob's solution is a good way to handle a single series of these unordered numbers by hand. (But note that not all the commas are followed by spaces).

This is a good example of why a good editor should support scripts.
Vongalin
Posts: 2
Joined: Wed Jan 02, 2008 9:00 pm

Post by Vongalin »

Bob Hansen wrote:Quick untested approach:

Replace comma-space with \n to make one value in each row.
Sort the single column
Replace each \n with comma-space.
Worked perfect. Thanks everyone for your tips/tricks.
Post Reply