Skip to content

Instantly share code, notes, and snippets.

@jreisinger
Created October 20, 2012 17:11
Show Gist options
  • Save jreisinger/3924052 to your computer and use it in GitHub Desktop.
Save jreisinger/3924052 to your computer and use it in GitHub Desktop.
mygrep
#!/usr/bin/perl
# Leave out comments and highlight regex
# Usage: $ mygrep [regex] <file>
# to compress blank lines: $ mygrep [regex] <file> | perl -00pe0
use strict;
use warnings;
use Term::ANSIColor;
my $regex = shift unless -f $ARGV[0];
while (<>) {
next if /\s*#/;
if ( $regex and /$regex/ ) {
print $`;
print color 'red';
print $&;
print color 'reset';
print "$'\n";
} else {
print "$_";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment