Replace Pioneer Home   All Examples   Free Download

 New request --free  RSS: Replace Pioneer Examples

1321.Text file parser -- How to extract random lines containing specified words?

User: Aaron -- 2015-11-03          << 1320  1322 >>
Hits: 1185
Type: Text file parser   
Search all Text file parser examples
Description:
I would like a version of script 1108 that extracts a single random line from multiple files that matches a word or phrase in a list and writes those single random lines to a new text file.
Input Sample:
Batch input files:

file1.txt

Bob drives his car.
I will travel to England.
Sue did not travel to Mexico.
Frank stayed home.
Did Mark travel to Europe?
etc.

file2.txt

Steve is going home.
I would like a new car.
The travel agency is closed.
The children are at home
Is travel to Europe expensive?
etc.

file3.txt

Should I travel by plane or boat?
She would like to travel to Europe.
He was in a car accident.
Is Joe still at home?
etc.
Output Sample:
Words and phrases in a list file:

home
car
travel to Europe
travel
etc.

Sample output text files:

New_file.txt

Frank stayed home.
I would like a new car.
She would like to travel to Europe.
The travel agency is closed.

or

New_file.txt

Steve is going home.
He was in a car accident.
Did Mark travel to Europe?
Should I travel by plane or boat?

etc.
Answer:
Hint: You need to Download and install "Replace Pioneer" on windows platform to finish following steps.
1. ctrl-o open the list file, e.g. d:\test\words.txt
2. ctrl-h open 'replace' dialogue:
* set 'replace unit' to 'Line'
* set 'replace with pattern' to:

* click 'advanced' tab:
set 'run following at the beginning of replace' to:

3. click 'replace', done.

Screenshot 1:  Replace_Window


Screenshot 2:  Replace_Advanced_Window


Similar Examples:
How to extract lines containg specified words from many files? (80%)
How to extract all lines containing words in specified file? (78%)
How to extract all sentences that contain specified words? (78%)
How to extract all lines that contain specific words in a file? (76%)
How to extract all lines that contain specified words or phrases? (76%)
How to extract all lines by specified words in group? (74%)
How to remove lines containing specified words in a text file? (73%)
How to extract sentences that contain specified words from UTF8 file? (71%)

Check Demo of Text file parser
Keywords:
extract random lines  how to extract random  matches  phrase  grep  random lines  unique  lines containing  specified words  write  extract line containing word from text file  extract lines from file containing  replace word with a random word from a list  extract lines containing word  replace list of words with a single word  replace multiple words in single file  extract line containing word  random word from a list