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

后端 未结 2 1126
太阳男子
太阳男子 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 12:00

    use Regexp::Common qw/net/;
    while (<>) {
      print $1, "\n" if /($RE{net}{IPv4})/;
    }
    

提交回复
热议问题