linux - Quickest way to remove 70+ strings from a file? -


i have 70+ strings need find , delete in file. need remove entire line in file string appears in.

i know can use sed -i '/string remove/d' filea.txt remove them 1 @ time. however, considering have 70+, take time doing way.

is there way can put these 70+ strings in file , have sed go through them 1 one? or if create file containing strings, there way compare 2 files removes line filea contains 1 of strings?

you use grep:

grep -vf file_with_words.txt file.txt 

where file_with_words.txt file containing list of words, each word being on different line , file.txt file want remove lines from.

if list of words contains regex metacharacters, tell grep consider fixed strings (if want):

grep -f -vf file_with_words.txt file.txt 

using sed, you'd need say:

sed '/word1\|word2\|word3/d' file.txt 

or

sed -e '/word1|word2|word3/d' file.txt 

you use command substitution construct pattern too:

sed -e "/$(paste -sd'|' file_with_words.txt)/d" file.txt 

but grep tool use in case.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -