Quote:
Originally Posted by syg00
Yes, I know it's grep, but that "P" is to use perl style regex ... (hint maybe)
|
Just a note: the -P flag isn't available on many versions or builds of
grep. (Also, the Perl-style regexes of
grep and many other tools and libraries aren't
really Perl regular expressions. That doesn't mean that they're bad or useless, but it can trip you up if you expect them to be identical to Perl's regexes.)
@kariageken: Rather than slurp the whole file in at once, I would read it in line by line. In terms of removing everything but the digits, I would do that using
map as I did the split. Here's an example:
Code:
#!/usr/bin/env perl
use strict;
use warnings;
open my $fh, '<', 'file' or die "Can't open 'file' for reading: $!";
while (my $line = <$fh>) {
if ($line =~ /^Mem:/) {
my @data = map { s/[^0-9]//g; $_ } split(/,\s+/, $line);
print "@data\n";
}
}