Sorting alphabetically line by line

Get help with installation and running here.

Moderators: DataMystic Support, Moderators

simoninsing
Posts: 18
Joined: Fri Jun 05, 2009 11:11 pm

Sorting alphabetically line by line

Postby simoninsing » Tue Mar 16, 2010 11:09 pm

Is there a function in TP that sorts text alphabetically line by line ?

Example:
apple, pear, tamarillo, orange, banana, "custard apple"
pear, tamarillo, orange, grapefruit, "custard apple", apple
tamarillo, orange, durian, "custard apple", apple, pear


becomes

apple, banana, "custard apple", orange, pear, tamarillo
apple, "custard apple", grapefruit, pear, tamarillo
apple, "custard apple", durian, orange, pear, tamarillo

User avatar
DataMystic Support
Site Admin
Posts: 2138
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Sorting alphabetically line by line

Postby DataMystic Support » Wed Mar 17, 2010 5:47 am

You can achieve this by restricting to a line at a time, breaking fields onto separate lines, sorting, and then rejoining the lines.

See attached.
Attachments
sort each line.zip
(690 Bytes) Downloaded 333 times
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

simoninsing
Posts: 18
Joined: Fri Jun 05, 2009 11:11 pm

Re: Sorting alphabetically line by line

Postby simoninsing » Wed Mar 17, 2010 9:04 am

Thanks. I can't import the .fll file you attached (says it comes from a later version of TP, although I appear to have the latest version [8.4.9.1] so maybe it's because I have Lite not Standard/Pro) but reading up on Restrictions now.

User avatar
AnthonyFitz
Posts: 11
Joined: Mon Aug 25, 2008 9:16 pm
Location: Dublin and Manila
Contact:

Re: Sorting alphabetically line by line

Postby AnthonyFitz » Wed Mar 17, 2010 10:45 am

Hi,

I have created a filter that will do this also using the restrict to each line in turn filter.

I tested it on the following input, and got the following output.

Input
apple, pear, tamarillo, orange, banana, "custard apple"
pear, tamarillo, orange, grapefruit, "custard apple", apple
tamarillo, orange, durian, "custard apple", apple, pear
Output
apple, banana, "custard apple", orange, pear, tamarillo
apple, "custard apple", grapefruit, orange, pear, tamarillo
apple, "custard apple", durian, orange, pear, tamarillo

Cheers,
Anthony.

Filter Text Export

Code: Select all

|--Restrict to each line in turn
|  |
|  |--Perl pattern ["] with []
|  |     [ ] Match case
|  |     [ ] Whole words only
|  |     [ ] Case sensitive replace
|  |     [ ] Prompt on replace
|  |     [ ] Skip prompt if identical
|  |     [ ] First only
|  |     [ ] Extract matches
|  |     Maximum text buffer size 4096
|  |     [ ] Maximum match (greedy)
|  |     [ ] Allow comments
|  |     [X] '.' matches newline
|  |     [ ] UTF-8 Support
|  |   
|  |--Perl pattern [, ??] with [\r\n]
|  |     [ ] Match case
|  |     [ ] Whole words only
|  |     [ ] Case sensitive replace
|  |     [ ] Prompt on replace
|  |     [ ] Skip prompt if identical
|  |     [ ] First only
|  |     [ ] Extract matches
|  |     Maximum text buffer size 4096
|  |     [ ] Maximum match (greedy)
|  |     [ ] Allow comments
|  |     [X] '.' matches newline
|  |     [ ] UTF-8 Support
|  |   
|  |--Remove blanks from Start of Line
|  |   
|  |--Remove blanks from End of Line
|  |   
|  |--Ascending ANSI sort (case insensitive)
|  |   
|  |--Perl pattern [^(.* .*)\r\n] with ["$1"\r\n]
|  |     [ ] Match case
|  |     [ ] Whole words only
|  |     [ ] Case sensitive replace
|  |     [ ] Prompt on replace
|  |     [ ] Skip prompt if identical
|  |     [ ] First only
|  |     [ ] Extract matches
|  |     Maximum text buffer size 4096
|  |     [ ] Maximum match (greedy)
|  |     [ ] Allow comments
|  |     [ ] '.' matches newline
|  |     [ ] UTF-8 Support
|  |   
|  +--Perl pattern [\r\n(?!\Z)] with [, ]
|        [ ] Match case
|        [ ] Whole words only
|        [ ] Case sensitive replace
|        [ ] Prompt on replace
|        [ ] Skip prompt if identical
|        [ ] First only
|        [ ] Extract matches
|        Maximum text buffer size 4096
|        [ ] Maximum match (greedy)
|        [ ] Allow comments
|        [X] '.' matches newline
|        [ ] UTF-8 Support
http://www.TheLocalizer.com/
High Quality, Low Cost, Localization Engineering, Testing, Audio & Video Services

simoninsing
Posts: 18
Joined: Fri Jun 05, 2009 11:11 pm

Re: Sorting alphabetically line by line

Postby simoninsing » Wed Mar 17, 2010 11:02 am

Many thanks Anthony. It looks great. I'll need to upgrade to Pro to use it, which I'll do soon ... as soon as I feel rich enough !

User avatar
DataMystic Support
Site Admin
Posts: 2138
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Sorting alphabetically line by line

Postby DataMystic Support » Wed Mar 17, 2010 12:08 pm

Sorry, I forgot I was using the 8.5 pre-release!

Code: Select all

|   
|--Perl pattern [, ] with [,]
|     [ ] Match case
|     [ ] Whole words only
|     [ ] Case sensitive replace
|     [ ] Prompt on replace
|     [ ] Skip prompt if identical
|     [ ] First only
|     [ ] Extract matches
|     Maximum text buffer size 4096
|     [ ] Maximum match (greedy)
|     [ ] Allow comments
|     [X] '.' matches newline
|     [ ] UTF-8 Support
|   
|--Restrict to each line in turn
|  |
|  |--EasyPattern [[ csvfield ]] with [$0\r\n]
|  |     [ ] Match case
|  |     [ ] Whole words only
|  |     [ ] Case sensitive replace
|  |     [ ] Prompt on replace
|  |     [ ] Skip prompt if identical
|  |     [ ] First only
|  |     [X] Extract matches
|  |     Maximum text buffer size 4096
|  |   
|  |--Ascending ANSI sort (case insensitive), length 50
|  |   
|  |--Perl pattern [\r\n] with [,]
|  |     [ ] Match case
|  |     [ ] Whole words only
|  |     [ ] Case sensitive replace
|  |     [ ] Prompt on replace
|  |     [ ] Skip prompt if identical
|  |     [ ] First only
|  |     [ ] Extract matches
|  |     Maximum text buffer size 4096
|  |     [X] Maximum match (greedy)
|  |     [ ] Allow comments
|  |     [X] '.' matches newline
|  |     [ ] UTF-8 Support
|  |   
|  +--Add footer [\r\n]
|     
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

User avatar
AnthonyFitz
Posts: 11
Joined: Mon Aug 25, 2008 9:16 pm
Location: Dublin and Manila
Contact:

Re: Sorting alphabetically line by line

Postby AnthonyFitz » Thu Mar 18, 2010 7:54 am

simoninsing wrote:Many thanks Anthony. It looks great. I'll need to upgrade to Pro to use it, which I'll do soon ... as soon as I feel rich enough !

Best purchase you'll ever make. You wont regret it!
http://www.TheLocalizer.com/
High Quality, Low Cost, Localization Engineering, Testing, Audio & Video Services


Return to “TextPipe Tips and Tricks, Questions and Support”

Who is online

Users browsing this forum: DataMystic Support and 1 guest