Replace Pioneer Home   All Examples   Free Download

 New request --free  RSS: Replace Pioneer Examples

166.Advanced search and replace -- How to join groups of lines together in a text file according to user defined rule?

User: editor -- 2008-05-30          << 165  167 >>
Hits: 2034
Type: Advanced search and replace   
Search all Advanced search and replace examples
Description:
How to join groups of lines together in a text file according to user defined rule?
Input Sample:
[item1]
line1
line2
line3
[item2]
line21
line22

[item3]
line31
line32
line33
Output Sample:
[item1] line1 line2 line3
[item2] line21 line22 
[item3] line31 line32 line33
Answer:
Hint: You need to Download and install "Replace Pioneer" on windows platform to finish following steps.
It's easy to use replace pioneer, just need to remove the line break which is not followed by a '['.
1. ctrl-o open source file.    
2. ctrl-h open 'Replace' dialog,    
in 'Replace' window,     
* fill in 'Search for Pattern':    

Note: \n+ means any of consecutive line breaks
* fill one space character in 'Replace with Pattern':

* fill the window under 'If':

Note: means the matched \n+ not followed by a '['
3. click 'Replace', finish.

Above operation means if a line is not followed by a '[' in next line, replace the line break with one space character.
Download Script:  scripts/166.rst.zip

Screenshot 1:  Replace_Window


Similar Examples:
How to split a text file according to specified tags? (63%)
How to join every 50 or 500 lines together in a text file? (62%)
How to sort the lines in a text files by the order of line length? (62%)
How to change text file format with user specified rules? (60%)
How to split a text file according to first word in each line? (58%)
How to convert the text format by user specified rules? (58%)
How to replace text files using multiple pre-defined rules? (57%)
How to refine multiple text files by specified rules? (56%)

Check Demo of Advanced search and replace
Keywords:
user defined  line breaks  groups  not followed  consecutive  onsecutive  line break  break  together  cut  replace pioneer remove space  remove consecutive space  remove line breaks replace pioneer  replace pioneer line break  lines under  remove breaks  remove line breaks  replace pioneer text rule