Hi,

Need some help with a regex please.

I need to search a file for every instance of a string that ends with %.
Think output from the df command.  I need the 1, 2 or 3 digits before the %
passed into the array.

Code:
#!/usr/bin/perl
use warnings;
use strict;

my $outfile2 = "XXX.dat";
open(DATA2, "< $outfile2") || die "Can't open $outfile2: $!\n";
while(<DATA2>) {
  my @oput2 = /\b([0-9]+)%/;
  print "XXX @oput2 XXX\n";
}
close(DATA2);

It is kind of working but I pick up stuff I don't want e.g:

Input data(XXX.dat):
head
123 123 111% 123
456 22% 456 456 456
789
tail

Output data:
XXX  XXX
XXX 111 XXX
XXX 22 XXX
XXX  XXX
XXX  XXX

How do I tell it not to process every line in the file, just the lines that
contain the relevant string?

Thanks,
Greg Keenan
Lucent Technologies * 
Level 1, 68 Waterloo Road
North Ryde NSW 2113
Australia
* +61 2 9491 6898 
* [EMAIL PROTECTED] 


Reply via email to