in reply to Filtering out IP addresses

This'll do it:

$ perl -nle 's/([0-9]?\d\d?|2[0-4]\d|25[0-5])\.([0-9]?\d\d?|2[0-4]\d|2 +5[0-5])\.([0-9]?\d\d?|2[0-4]\d|25[0-5])\.([0-9]?\d\d?|2[0-4]\d|25[0-5 +])/xxx.xxx.xxx.$4/; print' filename

Depending on what your file contains, this can be simplified a lot, though. If it's e.g. one IP address per line, the following will also be fine:

$ perl -nle 's/\d+\./xxx./g; print' filename

But in the presence of other data, it may or may not work as intended, and also note it neither cares about IP addresses having four fields, nor about each field ranging from 0 to 255, or in fact consisting of no more than three decimal digits.

When in doubt, I'd suggest using the first one, even if it's a bit unwieldy.

Replies are listed 'Best First'.
Re^2: Filtering out IP addresses
by kennethk (Abbot) on Jul 22, 2014 at 22:01 UTC
    perl -nle 's/\d+\./xxx./g; print' filename
    As long we're writing one-liners, that should probably be
    perl -ple 's/\d+\./xxx./g' filename
    See -p in perlrun.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      Oh, nice, I'd not been aware of -p yet. Thanks for the pointer!
Re^2: Filtering out IP addresses
by Anonymous Monk on Jul 23, 2014 at 15:18 UTC
    thank you, that was a really helpful answer. We need People like you who take time of their day to help a stranger. Perl monk is the best!
      Awww shucks, sugarcube. *tips hat* You're very welcome!