There are many examples on how to remove lines in one file when that same line exists in another file. I have read through them and they all remove if the full line matches. Examples like: grep -vxF -f file1 file2
What I have is slightly different. I have a list of URLs from my websites and my clients websites. I want to remove lines from that file when the domain matches a domain in another file.
So the first file might look like:
http://www.site1.com/some/path
http://www.site2.com/some/path
http://www.site3.com/some/path
http://www.site4.com/some/path
The second file could be:
site2.com
www.site4.com
I would like the output to be:
http://www.site1.com/some/path
http://www.site3.com/some/path
You have too many
grep
flags. Specifically:-x
will keep you from getting your desired results.Assuming that file1 has the patterns, and file2 has the URLs, just use:
The
-x
flag will keep you from getting the results that you want: using-x
means: match only against the entire line, i.e. only match a line if the line is exactly, e.g. site2.com.From the
man grep
:There may be some corner cases this doesn't handle, but you can simply use the
-v
and-f
options ofgrep
:The following should work (untested):