diff options
author | Florian Pritz <bluewind@xinu.at> | 2016-12-26 11:25:56 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2016-12-26 11:25:56 +0100 |
commit | 6c4b01440c0d4109b063677712d21740133eed4f (patch) | |
tree | 743ceec5ca371233d401d05e830445906c307192 /grep-group | |
parent | 9f902db6b0443e26b2886d81bae5e87a10531a6c (diff) | |
download | bin-6c4b01440c0d4109b063677712d21740133eed4f.tar.gz bin-6c4b01440c0d4109b063677712d21740133eed4f.tar.xz |
Add grep-group
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'grep-group')
-rwxr-xr-x | grep-group | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/grep-group b/grep-group new file mode 100755 index 0000000..06bc923 --- /dev/null +++ b/grep-group @@ -0,0 +1,31 @@ +#!/usr/bin/perl +use warnings; +use strict; +use File::Basename; + +if (@ARGV < 1) { + print "usage: cat | ", basename($0), " <regexp>\n"; + exit 2; +} + +my $pattern = shift; + +while (<>) { + my $line = $_; + chomp($line); + + if (my @matches = $line =~ /$pattern/) { + if ($#- != 0) { + if (scalar(@matches) == 1) { + printf "%s\n", $matches[0]; + } else { + for my $match (@matches) { + print $match; + } + printf "\n"; + } + } else { + printf "%s\n", $&; + } + } +} |