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:
I tried using xargs but it is just too tricky to get that IP address interpolated.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
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 |