Sunday, May 1, 2016

Perl Script to parse or read URL/URI and IP Address using regex

Perl Script to parse or read URL/URI and IP Address using regex

#!/usr/bin/perl
$file = '/home/adhoc/practice/temp1.txt';
open(FH,"$file") or die "couldn't open the file,$!";
while($line = <FH>)
{
if($line =~ m/\d{3}\.\d{3}\.\d{3}\.\d{3}/)
{
print "$line\n";
}
if($line =~ m/(http|https|ftp):\/\/www\.([a-zA-Z0-9\-]+\.([a-zA-Z]+)/)
{
print "$line\n";
}
}
close(FH);

No comments:

Post a Comment