Sorting alphabetically line by line
Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators
-
- Posts: 20
- Joined: Fri Jun 05, 2009 11:11 pm
Sorting alphabetically line by line
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
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
- DataMystic Support
- Site Admin
- Posts: 2227
- Joined: Mon Jun 30, 2003 12:32 pm
- Location: Melbourne, Australia
- Contact:
Re: Sorting alphabetically line by line
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.
See attached.
- Attachments
-
- sort each line.zip
- (690 Bytes) Downloaded 736 times
-
- Posts: 20
- Joined: Fri Jun 05, 2009 11:11 pm
Re: Sorting alphabetically line by line
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.
-
- Posts: 11
- Joined: Mon Aug 25, 2008 9:16 pm
- Location: Dublin and Manila
- Contact:
Re: Sorting alphabetically line by line
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
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
High Quality, Low Cost, Localization Engineering, Testing, Audio & Video Services
-
- Posts: 20
- Joined: Fri Jun 05, 2009 11:11 pm
Re: Sorting alphabetically line by line
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 !
- DataMystic Support
- Site Admin
- Posts: 2227
- Joined: Mon Jun 30, 2003 12:32 pm
- Location: Melbourne, Australia
- Contact:
Re: Sorting alphabetically line by line
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]
|
-
- Posts: 11
- Joined: Mon Aug 25, 2008 9:16 pm
- Location: Dublin and Manila
- Contact:
Re: Sorting alphabetically line by line
Best purchase you'll ever make. You wont regret it!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 !
http://www.TheLocalizer.com/
High Quality, Low Cost, Localization Engineering, Testing, Audio & Video Services
High Quality, Low Cost, Localization Engineering, Testing, Audio & Video Services