punitpawar has asked for the wisdom of the Perl Monks concerning the following question:
This is the sample input file abc.txt#!/usr/bin/perl use Data::Dumper; open(FH,"<abc.txt")or die EXPR; while (<FH>) { my @words = split(/ /,$_); foreach (@words) { if ($_=~/from:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/) { print "$1- \n"; }elsif ($_ =~/to:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/){ print "$1 \n"; } } } close (FH);
And the output I am expecting ishshhhgljlkjglgkjj from:198.18.66.5 aegighighighilg to:198.18.66.6 iiuf +duifuiuih from:198.18.66.7 hiihhj to:198.18.66.8 hhouhoho from:198.18.66.9 igilgojhjh to:198.18.6 +6.10 igighliho from:198.18.66.11 highighioouhouhhhoh to:198.18.66.12
198.18.66.5 ,198.18.66.6 198.18.66.7 ,198.18.66.8 198.18.66.9 ,198.18.66.10 198.18.66.11 ,198.18.66.12
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: To find and count a repeating pattern in a line
by poj (Abbot) on Feb 08, 2016 at 20:05 UTC | |
|
Re: To find and count a repeating pattern in a line
by neilwatson (Priest) on Feb 08, 2016 at 19:47 UTC |