Replace Pioneer Home   All Examples   Free Download

 New request --free  RSS: Replace Pioneer Examples

1157.Text file parser -- How to randomly delete some percent of lines that don't have bracket?

User: Aaron -- 2013-12-10          << 1156  1158 >>
Hits: 3246
Type: Text file parser   
Search all Text file parser examples
Description:
Thank you for script 1156. In a similar method what is the best way to randomly  
delete lines that don't contain text in brackets based on the same percentage  
calculation as script 1156?
Input Sample:
Line 1 aaaa   bbb   ccc  ddd  eee (some text in brackets) 
Line 2 aaaa  bbbbbb c dd eee 
Line 3 aaaa bbb cc dd ee  fff 
Line 4 (more text in brackets) 
Line 5 aaa bbb ccc d eee f ggg 
Line 6 aa (even more text) 
Line 7 a b ccc d e ff gg 
Line 8 aaaaa bbb ccc dd e ff gg (and more too) 
etc 
 
Randomly delete 50% of lines NOT containing (text in  brackets)
Output Sample:
Possible output: 
 
Line 1 aaaa   bbb   ccc  ddd  eee (some text in brackets) 
Line 2 aaaa  bbbbbb c dd eee 
Line 4 (more text in brackets) 
Line 5 aaa bbb ccc d eee f ggg 
Line 6 aa (even more text) 
Line 8 aaaaa bbb ccc dd e ff gg (and more too) 
 
or ... 
 
Line 1 aaaa   bbb   ccc  ddd  eee (some text in brackets) 
Line 3 aaaa bbb cc dd ee  fff 
Line 4 (more text in brackets) 
Line 6 aa (even more text) 
Line 7 a b ccc d e ff gg 
Line 8 aaaaa bbb ccc dd e ff gg (and more too) 
etc.
Answer:
Hint: You need to Download and install "Replace Pioneer" on windows platform to finish following steps.
1. ctrl-o open 'text' file 
2. ctrl-h open 'replace' dialogue 
* set 'replace with pattern' to: 
 
* click 'advanced' tab 
set 'run following for each matched unit' to: 
 
3. click 'replace', done. 
 
Note: you can adjust 0.5 to other values.

Screenshot 1:  Replace_Window


Screenshot 2:  Replace_Advanced_Window


Similar Examples:
How to randomly delete x number of lines from text inside and outside brackets? (71%)
How to randomly deletes x number of lines from text files? (62%)
How to randomly generate some of the permutation of paragraphs? (55%)
How to delete lines that start with duplicate text? (54%)
How to delete all lines that contain only a word and a blank? (53%)
How to randomly select one line from each paragraph? (53%)
How to replace line that contains no space? (52%)
How to merge lines with previous lines that ended with backslash? (51%)

Check Demo of Text file parser
Keywords:
brackets  best  adjust  bracket  ray  array  similar  based on  what  unique  ctrl h replace brackets  split text file based on pattern  similar lines  sort randomly  join sort split match n  delete tab  advanced text file parser  join 2 lines if