I have a file containing a list of words. I want to remove all occurrences of all the words in this file from a big text file.
Example:
File 1
queen
king
Text file sample
Both the king and queen are monarchs. Will the queen live? Queen, it is!
This is what I have tried:
sed -i 's/queen/ /g' page.txt
sed -i 's/Queen/ /g' page.txt
Output
Both the and are monarchs. Will the live? , it is!
The list of words I have is big (over 50000 words). How can I do this without having to specify the pattern in the command line?
queen,
matchesqueen
)? How about substrings? Shouldking
matchhiking
? Orhigh-king
? – terdon Nov 10 '16 at 12:26sed
allows to submit expressions from a file via its option-f
. You could even writesed
"programs" by prepending#!/usr/bin/sed -f
to such a file and giving it execute permissions. However, with 50000 expressions I agree thatsed
seems to be an inappropriate choice. – countermode Nov 10 '16 at 14:02