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

后端 未结 2 1134
太阳男子
太阳男子 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/;
    }
    

提交回复
热议问题