Re: Find string ending with %
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Tue, 16 Aug 2005 17:45:10 -0700
Keenan, Greg John (Greg)** CTR ** wrote:
> Hi,
Hello,
> 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?
while(<DATA2>) {
my @oput2 = /(\d+)%/ or next;
print "XXX @oput2 XXX\n";
}
John
--
use Perl;
program
fulfillment
.
- References:
- Find string ending with %
- From: Greg John ** CTR ** Keenan
- Find string ending with %
- Prev by Date: Unitialized value in hash element problem...
- Next by Date: RE: A sript to delete programs installed from source
- Previous by thread: Find string ending with %
- Next by thread: RE: Find string ending with %
- Index(es):
Relevant Pages
|