From: Tollef Fog Heen Date: Thu, 31 Jan 2013 17:04:08 +0000 (+0100) Subject: Rename and update X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=555da9acde353b05a413c067963708206a4ed366;p=moreutils Rename and update --- diff --git a/Makefile b/Makefile index be379ab..283826c 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ BINS=isutf8 ifdata ifne pee sponge mispipe lckdo parallel errno -PERLSCRIPTS=vidir vipe ts combine zrun chronic -MANS=sponge.1 vidir.1 vipe.1 isutf8.1 ts.1 combine.1 ifdata.1 ifne.1 pee.1 zrun.1 chronic.1 mispipe.1 lckdo.1 parallel.1 errno.1 +PERLSCRIPTS=vidir vipe ts combine zrun chronic curiouscat +MANS=sponge.1 vidir.1 vipe.1 isutf8.1 ts.1 combine.1 ifdata.1 ifne.1 pee.1 zrun.1 chronic.1 mispipe.1 lckdo.1 parallel.1 errno.1 curiouscat.1 CFLAGS?=-O2 -g -Wall INSTALL_BIN?=install -s PREFIX?=/usr diff --git a/curiouscat b/curiouscat index 97c065c..48118c2 100755 --- a/curiouscat +++ b/curiouscat @@ -1,26 +1,26 @@ -#!/usr/bin/perl +#!/usr/bin/perl -l =head1 NAME -cgrep - grep the output of a command, only printing stdout/stderr if match +curiouscat - grep the output of a command, only printing stdout/stderr if match =head1 SYNOPSIS -cgrep [-v] PATTERN COMMAND... +cgrep [-v] [-f PATTERNFILE | PATTERN ] COMMAND... =head1 DESCRIPTION -cgrep runs a command, buffering the output from both standard out and -standard error, looking for a matching pattern. If a matching pattern -is found, stdout and stderr are printed and cgrep exits with the exit -code of COMMAND. +curiouscat runs a command, buffering the output from both standard out +and standard error, looking for a matching pattern. If a matching +pattern is found, stdout and stderr are printed and curiouscat exits +with the exit code of COMMAND. -If the -v switch is passed, cgrep switches into reverse mode where it -will print if there are any lines not matching PATTERN. +If the -v switch is passed, curiouscat switches into reverse mode +where it will print if there are any lines not matching PATTERN. =head1 AUTHOR -Copyright 2010 by Collabora Limited, written by Tollef Fog Heen +Copyright 2010, 2013 by Collabora Limited, written by Tollef Fog Heen Licensed under the GNU GPL. @@ -34,10 +34,19 @@ use IPC::Run qw( start pump finish timeout ); $|=1; my $reverse = 0; +my @patterns = (); +my $patternfile; use Getopt::Long; -GetOptions("v" => \$reverse) || die "usage: cgrep [-v] PATTERN COMMAND...\n"; +GetOptions("v" => \$reverse, + "f=s" => \$patternfile) || die "usage: cgrep [-v] [-f PATTERNFILE | PATTERN ] COMMAND...\n"; -my $pattern = shift @ARGV; +if (defined $patternfile) { + my $p; + open $p, "<", $patternfile or die "Can't open $patternfile: $!"; + chomp(@patterns = <$p>); +} else { + @patterns = (shift @ARGV); +} my @command = @ARGV; my ($in, $out, $err); @@ -46,14 +55,26 @@ my $h = IPC::Run::start \@command, \*STDIN, \$out, \$err; $h->finish; if ($reverse) { - if ($out !~ /$pattern/m and $err !~ /$pattern/m) { - print STDOUT $out; - print STDERR $err; + for my $line (split(/$\//, $out), split(/$\//, $err)) { + my $nomatch = 1; + for my $p (@patterns) { + if ($line =~ /$p/m ) { + $nomatch = 0; + last; + } + } + if ($nomatch) { + print STDOUT $out; + print STDERR $err; + last; + } } } else { - if ($out =~ /$pattern/m or $err =~ /$pattern/m) { - print STDOUT $out; - print STDERR $err; + for my $p (@patterns) { + if ($out =~ /$p/m or $err =~ /$p/m) { + print STDOUT $out; + print STDERR $err; + } } } exit $h->result or 0;