Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 28 lines (23 sloc) 0.666 kB
#!/usr/bin/perl
# regex is the first argument
#
# if there are more arguments, then it will treat them as files to read
# e.g. plgrep foo myfile.txt
#
# otherwise it reads from STDIN
# e.g. cat myfile.txt | plgrep foo
my $pattern = shift @ARGV;
while ( my $line = <> ) {
if ( my @matched = $line =~ $pattern ) {
# there were captures in the regex
# so display what was captured
if ( scalar @matched and $matched[0] ne '1' ) {
print join(' ', @matched), "\n";
}
# otherwise the regex just matched on a line
# so display the whole line
else {
print $line;
}
}
}
Jump to Line
Something went wrong with that request. Please try again.