Sorting alphabetically line by line

Get help with installation and running here.

Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators

Post Reply
simoninsing
Posts: 20
Joined: Fri Jun 05, 2009 11:11 pm

Sorting alphabetically line by line

Post by simoninsing »

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: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Sorting alphabetically line by line

Post by DataMystic Support »

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 734 times
simoninsing
Posts: 20
Joined: Fri Jun 05, 2009 11:11 pm

Re: Sorting alphabetically line by line

Post by simoninsing »

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.
AnthonyFitz
Posts: 11
Joined: Mon Aug 25, 2008 9:16 pm
Location: Dublin and Manila
Contact:

Re: Sorting alphabetically line by line

Post by AnthonyFitz »

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: 20
Joined: Fri Jun 05, 2009 11:11 pm

Re: Sorting alphabetically line by line

Post by simoninsing »

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: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Sorting alphabetically line by line

Post by DataMystic Support »

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]
|      
AnthonyFitz
Posts: 11
Joined: Mon Aug 25, 2008 9:16 pm
Location: Dublin and Manila
Contact:

Re: Sorting alphabetically line by line

Post by AnthonyFitz »

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
Post Reply