5 curiouscat - grep the output of a command, only printing stdout/stderr if match
9 cgrep [-v] [-f PATTERNFILE | PATTERN ] COMMAND...
13 curiouscat runs a command, buffering the output from both standard out
14 and standard error, looking for a matching pattern. If a matching
15 pattern is found, stdout and stderr are printed and curiouscat exits
16 with the exit code of COMMAND.
18 If the -v switch is passed, curiouscat switches into reverse mode
19 where it will print if there are any lines not matching PATTERN.
23 Copyright 2010, 2013 by Collabora Limited, written by Tollef Fog Heen
24 <tollef.fog.heen@collabora.co.uk>
26 Licensed under the GNU GPL.
32 use IPC::Run qw( start pump finish timeout );
40 GetOptions("v" => \$reverse,
41 "f=s" => \$patternfile) || die "usage: curiouscat [-v] [-f PATTERNFILE | PATTERN ] COMMAND...\n";
43 if (defined $patternfile) {
45 open $p, "<", $patternfile or die "Can't open $patternfile: $!";
46 chomp(@patterns = <$p>);
48 @patterns = (shift @ARGV);
53 my $h = IPC::Run::start \@command, \*STDIN, \$out, \$err;
58 for my $line (split(/$\//, $out), split(/$\//, $err)) {
60 for my $p (@patterns) {
61 if ($line =~ /$p/m ) {
73 for my $p (@patterns) {
74 if ($out =~ /$p/m or $err =~ /$p/m) {