Replace Pioneer Home   All Examples   Free Download

 New request --free  RSS: Replace Pioneer Examples

426.Advanced search and replace -- How to sort the lines in a text files by the order of line length?

User: editor -- 2010-02-20
Hits: 133
Type: Advanced search and replace   
Search all Advanced search and replace examples
Description:
How to sort the lines in a text files by the order of length?
I have a text file that has many lines with different number of characters, how to sort them by the order of the length? The shorter line will be in the front of the longer line.
Input Sample:
replace
search
test
application
parse
utilities
Output Sample:
test
parse
search
replace
utilities
application
Answer:
Hint: You need to Download and install "Replace Pioneer" to finish following steps.
1. Add a number in the front of each line, indicating the length of the line.
(1) ctrl-o open source text file
(2) ctrl-h open replace dialog
* set 'Replace Unit' to Line
* fill following in 'Replace with Pattern':

(3) click 'Replace', the number is added in the front of each line.
2. Sort the lines
(4) ctrl-h open 'Replace' dialog
(5) fill following in 'Replace with pattern' window:

(6) click 'Replace', text is sorted
3. Remove the numbers
(7) ctrl-h open 'Replace' window
* set 'Replace Unit' to 'Lines'
* set 'Replace with Pattern' to:

(8) click 'Replace', number removed
(9) ctrl-s save to file.
Download Script:  scripts/426.rst.zip

Similar Examples:
How to sort all the lines of a text file by order the multiple columns? (80%)
How to sort all the lines of a text file randomly? (67%)
How to convert each line of a text file to the new format? (65%)
How to sort all lines of text by specified keyword? (62%)
How to sort the text file by the date at the beginning of each line? (60%)
How to join groups of lines together in a text file according to user defined  rule? (60%)
How to convert many html files to text files all at once? (60%)
How to replace all the numbers in a text file to the square value? (59%)

Check Demo of Advanced search and replace