Posts Tagged ‘console’
Highlighting anything, using bash and sed
While writing code for SqueezeCenter or Jive, I found that I was struggling to easily mentally grep all the passing messages.
But no more! This quick hacky bash function (which I’ve put in my .bashrc) will let us run any command-line script and highlight a word.
highlight() { param=$1; shift; $* | sed "s/\($param\)/\x1B\[31;1m\1\x1B\[0m/gI"; }
For example, to run the software ‘jive’ program, looking for the text ‘livedepartures’:
highlight livedepartures ./jive
Yes, it could be improved, but it does the job well enough for me…
Tags: bash, console, grep, highlight, sed
Filed under tech :
Comments (0) :
Feb 6th, 2008