in reply to one liner with separate input file?

If the substitution doesn't match, then the substitution is not performed, so all you need to do is combine the two one liners that you have into one:

perl -pi -e's/^(66.11.10.20)/#$1/g' ips.txt

Now then, stepping through the list of IP addresses is another issue. I would recommend using a script for this rather than a one liner.

Update: i'm sticking to my case, but this is too much fun. :) Let's say you have 2 text files, one containing the list of all IP addresses (all_IPs.txt) and another containing a smaller list of IP addresses to be commented out in the first text file (decomission_IPs.txt). You could use the shell to create individual strings that contain the Perl one-liners that can in turn be fed back to a shell:

for i in `cat decomission_IPs.txt`; do perl -le $"print 'perl -pi -e \ +'s/^(\Q$i\E)/#\$1/g\' all_IPs.txt' "; done | sh
I tried using xargs but it is just too tricky to get that IP address interpolated.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

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

    I tried your solution with a for..do loop, but it did not work. It appeared to be running for a small amount of time, but did not do any edits. I tried to run it from ksh and bash, and tried to specify ksh and bash in place of sh, but got no joy.

    I thought about trying to do this in xargs, but I too had problems getting it correct. That is why I thought perl might be better.

    There are more details in the back story of how I got to this point, but I wasn't sure it was needed for the perl discussion.