Reputation: 1631
I have two files:
Both files has a phrase on each line like this:
some phrase 1
some phrase 2
some phrase 3
Is there a way I can remove all the lines that are in the "Phrases to exclude" file from the main "Phrases" file?
The phrases are exact -- so only the entire line needs to be matched.
Upvotes: 1
Views: 69
Reputation: 118271
You can do as below also :
data_from_main_file = File.readlines('Phrases.txt')
data_to_exclude = File.readlines('Phrases-to-exclude.txt')
File.write('output.txt', (data_from_main_file - data_to_exclude).join)
Upvotes: 0
Reputation: 23939
phrases = File.read('Phrases.txt').lines
exclude = File.read('Phrases-to-exclude.txt').lines
File.write('Result.txt', (phrases - exclude).join)
Upvotes: 3