How do I take a list and remove it from a file?
grep -Fxf list -v /etc/remotedomains > remotedomains.new
mv remotedomains.new /etc/remotedomains
The -v
tells grep to only output lines that don't match the pattern.
The -f list
tells grep to read the patterns from the file list
.
The -F
tells grep to interpret the patterns as plain strings, not regular expressions (so you won't run into trouble with regex meta-characters).
The -x
tells grep to match the whole line, e.g. if there's a pattern foo
that should only remove the line foo
, not the line foobar
or barfoo
.