From 7ffcfbbfc93f1ee5e23945e6a30110f7aaf8ee47 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Wed, 21 Jan 2015 01:18:45 +0100 Subject: regcheck.pl: support multiline files, extend output Signed-off-by: Florian Pritz --- regcheck.pl | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'regcheck.pl') diff --git a/regcheck.pl b/regcheck.pl index a89b562..aa7929c 100755 --- a/regcheck.pl +++ b/regcheck.pl @@ -3,26 +3,34 @@ use warnings; use strict; use File::Basename; -if (@ARGV < 2) { - print "usage: ", basename($0), " \n"; +if (@ARGV < 1) { + print "usage: cat | ", basename($0), " \n"; exit 2; } my $pattern = shift; -for my $string (@ARGV) { - if (my @matches = $string =~ /$pattern/) { - print "\e[0;32mmatches:\e[0m "; +my $line_counter = 0; +while (<>) { + $line_counter++; + my $line = $_; + chomp($line); + + if (my @matches = $line =~ /$pattern/) { if ($#- != 0) { - print "\n"; my $counter = 0; - for my $match (@matches) { - print $counter++.": \"".$match."\"\n"; + if (scalar(@matches) == 1) { + printf "\e[0;32mmatched group\e[0m \e[0;38;5;12m%s\e[0m in line %d (%s)\n", $matches[0], $line_counter, $line; + } else { + printf "\e[0;32mmatched %d groups\e[0m in line %d (%s):\n", scalar(@matches), $line_counter, $line; + for my $match (@matches) { + print "\t".$counter++.": \e[0;38;5;12m".$match."\e[0m\n"; + } } } else { - print "$&\n"; + printf "\e[0;32mmatched\e[0m \e[0;38;5;12m%s\e[0m in line %d (%s)\n", $&, $line_counter, $line; } } else { - print "\e[0;31mno match\e[0m\n"; + #print "\e[0;31mno match\e[0m\n"; } } -- cgit v1.2.3-24-g4f1b