Replace Pioneer Home   All Examples   Free Download

 New request --free  RSS: Replace Pioneer Examples

560.Text file parser -- How to remove all the lines that do not contain any of words in a list?

User: editor -- 2010-07-09
Hits: 66
Type: Text file parser   
Search all Text file parser examples
Description:
How to filter out all the lines that containing any of word in a list?
Input Sample:
word_list.txt
word1
word2
word3
...

input.txt
.....word1......
...............
....word2........
..word3...........
.................
Output Sample:
output.txt
.....word1......
....word2........
..word3...........
Answer:
Hint: You need to Download and install "Replace Pioneer" to finish following steps.
1. ctrl-o open word_list.txt
2. ctrl-h open 'replace' window
* in 'search for pattern', enter:

* in 'replace with pattern', enter:

3. click 'Replace', you will get words separated by "|", like: word1|word2|word3..., copy the string to clipboard

4. ctrl-o open input.txt
5. ctrl-h open replace window
* set 'replace unit' to 'Line'
* in 'search for pattern' paste the string get in step 3:

Note: can not be "word1|word2|word3|", need remove trailing "|"
* in 'replace with pattern' enter 
* uncheck option of "Print Unmatched Unit"
6. click "Replace", done!
7. ctrl-s save to output.txt
Download Script:  scripts/560.rst.zip

Similar Examples:
How to remove all lines that contains more than one word? (75%)
How to extract all lines that contain words A and B and C? (69%)
How to remove all lines that are not ended with word "ok" or "done"? (68%)
How to find out all files that contain all words of A, B and C? (65%)
How to remove all folders in a list containg folders and files? (64%)
How to remove all duplicated lines without considering the last word? (64%)
How to findout all lines that contain specified words in multiple files? (63%)
How to extract all lines that contain A, but not any of B C D? (63%)

Check Demo of Text file parser