in reply to one liner with separate input file?

I agree with jeffa that this is getting a bit complicated for a one-liner. But a one-liner does not have to be only one line. Or you might want to call it a "two-liner". This compiles cleanly, but I haven't really tested it with actual data. Besides, it certainly does not take care of edge cases. This is just a clue for a possible pure Perl (no Bash) solution.
perl -pi -e 'BEGIN{ local @ARGV = ("IP_addr.txt"); %IP = map {$_ => 1; +} <>; } $_ = "#" . $_ if /((\d{1,3}\.){3}(\d{1,3}))/ and exists $IP{$1} +;'

Je suis Charlie.

Replies are listed 'Best First'.
Re^2: one liner with separate input file?
by MrGibbs (Initiate) on Apr 15, 2015 at 20:01 UTC
    Thanks for responding Laurent_R.

    I don't think I need to worry about the edge cases. I did several steps before I got here, with massaging and normalizing the data. Your solution is like jeffa's. It seemed to execute, but did not edit the file to be worked on. I did add the name of that file to the end of the command you suggested.

    I'll keep poking at this as time permits.

      True, I forgot to add the name of the file at the end of the command line. Sorry about that.

      But I can't say what went wrong with what you are saying in your comments.

      Please give full details on what you are trying: exact command line used, sample input files, OS on which you are working, any other thing worth of interest (such as warnings or errors).

      Je suis Charlie.
        Hi Laurent_R.

        Over the past few days, I've been continuing to work on doing this in a perl script instead of a one-liner. I have made some progress. I does exactly what I want when the ip_addr file contains 1 ip address. I tested it again with 3, and it does the first ip address, and does not do the 2nd or 3rd. I figure if I can do it for 3, then I can do it for N ip addresses.

        I'm doing this in Solaris 10, to answer your question. The current sate of the script is a mess with comments and print statements akimbo.

        If this was vi, I'd be doing this:
        :g/66.11.22.23/s/^/#/

        The problem is that I have several hundred ip addresses. Thanks for the response, regardless.