| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
On 2014-11-03 04:58, [email protected] [sed-users] wrote:
> But .. I have two files.
>
> FIle1
[snip]
>
> File2
[snip]
> I want to use file one to search file two. If ips in file one are
> matched in file2, I want to delete them and write a file of non
> matched ips.
[snip]
> ofcourse there are special considerations 10.10.10.1, 10.10.10.10,
> 10.10.10.100 .. need exact matches.
While it should be possible to do some complex manipulations in sed,
the fastest/easiest way to do it is with grep. I'm not sure if
there's anything GNU-specific about it, but I used your examples and
ran
grep -Fxvf file_to_exclude.txt file_with_data.txt > output.txt
The "-F" flag looks for fixed strings rather than regular
expressions (germane because you have a "." metacharacter in your
search terms). The "-x" flag requires whole-line matches rather than
partial matches (takes care of your "10.10.10.100" concern). The
"-v" flag inverts the search (looking for lines that *don't*
match). Finally, the "-f [filename]" flag looks for the patterns
defined in a file rather than on the command-line.
If you really do want a sed solution, I can try and cook one up, but
it will be far less understandable than this one.
-tim