I have a file that contains some info including IP addresses like below (a line may contains more than one IP):
ip_group1,1.2.3.4,otherstring1,otherstring2,4.5.6.7
ip_group2,3.4.5.6,otherstring1
ip_group3,11.21.31.41,otherstring1,otherstring2,4.5.6.7,otherstring4,1.2.3.4,otherstring5,otherstring2,41.51.16.71
I am using this portion of the Perl code to extract the IPs, but it only extracts the first occurrence of the IP and leaves the other IPs present in the line and process the next.
use Regexp::Common qw/net/;
while (<>) {
print $1, "\n" if /($RE{net}{IPv4})/;
}
How to get all the IPs present in a line?
My expected output is below:
ip_group1,1.2.3.4,4.5.6.7
ip_group2,3.4.5.6
ip_group3,11.21.31.41,4.5.6.7,1.2.3.4,41.51.16.71