in reply to one liner with separate input file?

You want bash/ksh do the hard work, just run this:

while read ip;do perl -pi -e s/^/#/ if /$ip/ script_file; done < ip_ad +dr_file

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

    I tried your suggestion of a while loop, with redirect in. I am using a test file of 5 ip addresses instead of the whole list. I also have a copy of the original script to see how each solution works. The stdout produced:

    Can't open if: No such file or directory.
    Can't open /66.22.11.24/: No such file or directory.
    Can't open if: No such file or directory.
    Can't open /66.22.44.28/: No such file or directory.
    Can't open if: No such file or directory.
    Can't open /66.22.44.18/: No such file or directory.
    Can't open if: No such file or directory.
    Can't open /66.33.22.23/: No such file or directory.
    Can't open if: No such file or directory.
    Can't open /66.33.22.24/: No such file or directory.

    The script did get modified, but it put a "#" at the begining of every line, and repeated it 5 times.

      hmm, somehow the quotes did not survive, I meant:

      while read ip;do perl -pi -e "s/^/#/ if /$ip/" script_file; done < ip_ +addr_file

      Also, if you do not want to match 1.2.3.444 with 1.2.3.4, then \b could help:
      while read ip;do perl -pi -e "s/^/#/ if /\b$ip\b/" script_file; done < + ip_addr_file

      And yes, it modifies the file immediately, and if you run it multiple times, it will keep adding #'s to each line that needs to be REMarked.
      In order to NOT do that, I finally propose:
      while read ip;do perl -pi -e "s/^#?/#/ if /\b$ip\b/" script_file; done + < ip_addr_file

      Drawbacks: It will iterate over the full file for each IP address. There are other solutions proposed, like the one with map, which is more efficient and faster.