Not sure I get it, but would

/^fc3\/2\b/ 

(assuming you're looking for fc3/2 and not fc3/23) work?

hth
paolino

On 23 Aug 2013, at 17:06, jet speed <speedj...@googlemail.com> wrote:

> Chaps,
> 
> Please i need help on the regular expression, i have the sample code below.
> I only want to match the entries from the array to the file and print the 
> matching line
> 
> for example if i only want to match fc3/23, in my code it prints both the 
> lines fc3/2 and fc3/23. How to restrict to exact matches and print only ex: 
> fc3/23
> 
> 
> 
> out.txt 
> ------
> 
> fc3/2  10:00:00:00  host1
> fc3/23 10:00:00:00  host2
> fc10/1 10:00:00:00  host3
> fc10/11 10:00:00:00  host4
> fc3/1 10:00:00:00  host5
> fc3/14 10:00:00:00  host6
> fc12/1 10:00:00:00  host7
> fc12/12    10:00:00:00  host8
> 
> 
> sample code 
> -----------------
> 
> my @check = (fc3/23, fc10/1, fc3/14, fc12/12);
> 
> my $f2 = 'out.txt';
> for my $element(@check) {
> open my $fh2, '<', $f2 or die "could not open $f2: $!";
> while (my $line = <$fh2>) {
> chomp $line;
> if ($line = / ^(fc\d+\/\d+/) {
> $match=$&;
> }
> if  ($element =~ $match) {
> print "$line \n";
> }
> }
> }
> 
> 
> required output
> --------------------
> 
> fc3/23 10:00:0:00  host2
> fc10/1 10:00:0:00  host3
> fc3/14 10:00:00:00  host6
> fc12/12    10:00:00:00  host8
> 
> Thanks
> Sj
> 


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to