How to extract IP addresses from a text file using Perl?

后端 未结 2 1050
太阳男子
太阳男子 2021-01-05 11:31

How do I extract just the IP addresses from a text file which has an IP address per line? I would like to extract the IPs and then list the IP addresses in a separate file.

相关标签:
2条回答
  • 2021-01-05 11:49
    
    while(<>)
    {
      print "$1\n" if /\b(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\b/;
    }
    
    0 讨论(0)
  • 2021-01-05 12:00
    use Regexp::Common qw/net/;
    while (<>) {
      print $1, "\n" if /($RE{net}{IPv4})/;
    }
    
    0 讨论(0)
提交回复
热议问题