Created
October 20, 2012 17:11
-
-
Save jreisinger/3924052 to your computer and use it in GitHub Desktop.
mygrep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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