Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

12
  • can you create two very small sample files (no need compressed, plain needed for testing) - and show what you expect from the grep command? I don't think you can specify both a positive search string and a negative one in same command.. you'll have to pipe output of one to the other, or may be possible with PCRE (but expensive, piping may still be faster) Commented Jul 10, 2019 at 13:45
  • 1
    try grep -f foo.txt ip.txt | grep -v Duplicate .. also, you can remove all the backslashes from foo.txt and use grep -Ff foo.txt ip.txt | grep -v Duplicate.. I would further suggest to use grep -wFf foo.txt ip.txt | grep -v Duplicate to avoid 10.10.0.28 matching something like 10.10.0.282 or 210.10.0.28 Commented Jul 10, 2019 at 15:24
  • I do not want to pipe it in to a "-v" as i don't have space to handle the temp file that will balloon as a result of including the "duplicate" lines Commented Jul 10, 2019 at 16:11
  • I'd modify foo.txt to have (?!.*Duplicate) starting each line and have zgrep use -P so that the negative lookahead works. Also, Sundeep's got a good point about substrings... might use \b at the start and end of each IP to ensure there's a word boundary. Commented Jul 10, 2019 at 16:25
  • @stevesliva when i used -P i got the error message "grep: the -P option only supports a single pattern" Commented Jul 10, 2019 at 16:30