Maybe something like this already exists, but I just wrote a quick little script that I call "highlight." It takes one argument, then reads STDIN and highlights that string on output with ANSI coloring (red).
#!/usr/bin/perl
my $word = shift;
while (<>) {
s/\Q$word\E/\e[31m$word\e[0m/g;
print;
}
So I can do fun things like:
% somebigdebuggingoutput | highlight 'what i am looking for'
It works great in conjunction with ls, locate, grep, etc.
Cool! (Score:2)
That just went into my bin/ directory. Thanks!
At my last job, we used something similar to color the output of our tests. Failed tests showed up in red. Hmm...
grep? (Score:2)
Re:grep? (Score:2)
Advent advocate (Score:1)
And with Term::ANSIColor [perladvent.org] you don't even have to remember or look up what the code for red is :-)
(I know...why complicate a perfectly simple thing :)
Re:Advent advocate (Score:2)
Re:Advent advocate (Score:2)
Here's a version that uses Term::ANSIColor and takes a -c option to define the colour used.
Might want to add some code checking the contents of $opt{c} before running "eval" on it.
Re:Advent advocate (Score:1)
I wonder why everyone uses the
:constantsinterface andeval()s their command line parameters. I've seen this meme in half a dozen different places now. The module has a perfectly good functional interface that makes this use case clearer too:Re:Advent advocate (Score:1)
Re:Advent advocate (Score:1)
Yup - already exists (Score:1)
they both seem to suffer from not being able to pipe the output into less and being bashisms though.
Re:Yup - already exists (Score:2)
less will work fine so long as you use the -R flag [greenwoodsoftware.com]. Or stuff it in $LESS if you dislike specifying it every time.
-Dom
Re:Yup - already exists (Score:1)
Leather appointed version! (Score:1)
Holy hell did those
@-and@+semantics ever turn my brain to mush. This was far harder than it promised to be.Re:Leather appointed version! (Score:2)
Re:Leather appointed version! (Score:1)
Re:Leather appointed version! (Score:2)
Re:Leather appointed version! (Score:1)
Thanks, but your fix is wrong. It introduces a bug in my initial tests. Apparently neither of us tested with sufficiently diverse patterns. The real fix is:
Yeah, I know what you're thinking. D'oh.
At this point I realized that it almost looked like a common rather than a special case and
Re:Leather appointed version! (Score:2)
The bug I was concerned with initially was that extra colors should be ignored, and if insufficient colors are provided, then the uncolored captures should get the same color as the uncaptured matched text.
The bug that sidetracked me was the handling of nested matches.
I'd be curious to hear if this monstrosity [perl.org] correctly handled your test cases too..