Skip to content

Commit

Permalink
Updated pgrep from original source at: http://perl.plover.com/classes…
Browse files Browse the repository at this point in the history
  • Loading branch information
sensespidey committed Apr 20, 2010
1 parent 7e910f4 commit 0c0f988
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions bin/pgrep
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ getopts($opts) or usage();
my $pat = defined($opt_e) ? $opt_e : @ARGV ? shift : usage();
my $qr = $opt_i ? qr/$pat/i : qr/$pat/;

$| = 1 if $opt_u;

my $format;

if (defined $opt_F) {
$format = $opt_F . "\n";
$format = $opt_F . "\n";
} else {
my %format = ( l => '%s'."\n",
h => '%2$s'."\n",
q => "",
"" => $opt_I || @ARGV > 1 ? "%s: %s\n" : '%2$s'."\n",
);
my %format = (l => '%s'."\n",
h => '%2$s'."\n",
q => "",
"" => $opt_I || @ARGV > 1 ? "%s: %s\n" : '%2$s'."\n",
);
my $fk = "";
$fk .= 'l' if $opt_l;
$fk .= 'h' if $opt_h;
$fk .= 'q' if $opt_q;
$format = $format{$fk};
unless (defined $format) {
warn "Incompatible options.\n";
usage();
warn "Incompatible options.\n";
usage();
}
}

$| = 1 if $opt_u;

$rc = 1; # No matches;

if ($opt_I) {
Expand All @@ -56,6 +56,7 @@ sub do_file {
return;
}
}

while (<$fh>) {
chomp;
if (/$qr/ ^ $opt_v) {
Expand All @@ -65,3 +66,22 @@ sub do_file {
}
}
}

sub usage {
print STDERR <<EOM;
Usage: $0 [$opts] pattern files...
-F format printf-style output format
(%1\$s = filename, %2\$s = text, %3\$d = line number)
-e pattern specify pattern
-h omit filenames
-i case-insensitive match
-I list of files on STDIN instead of in ARGV
-l print filenames only
-q print nothing
-u make output unbuffered
-v invert matching
EOM
exit 2;
}

0 comments on commit 0c0f988

Please sign in to comment.