hl (hilight)

Friday, 17 Dec 2004 [Monday, 4 Jan 2016]

This is a little Perl script you can use to highlight patterns matches in input data.
Share and enjoy.

usage: hl [ -c color ] [ -x ] pattern [ file... ] [ < input ]

 The pattern is a Perl regular expression which will
 be applied to each line of input, repeatedly (using
 the /g flag), after removing the newline.

 The -x switch suppresses lines without any matches.

 The -c switch specifies the colour to highlight the
 matched portion(s) of the line. By default this is
 bold green.

 Capture groups in the pattern can be used to highlight
 individual areas in each match. Pass a comma-separated
 list of colours to -c to use this feature. The second
 colour will be used to highlight the first capture,
 the third colour for the second capture, etc. If there
 are more captures than colours, the extra captures are
 highlighted in the same colour as the overall match.

 You can set the HILIGHT_COLORS environment variable to
 your favorite colors to avoid having to pass -c every
 time. E.g., in your .bashrc:

 export HILIGHT_COLORS='cyan, green, yellow, magenta,'\
 'blue, red, blue on_yellow, red on_white, bold green'

 Passing -c explicitly will override the environment.

 Note: in case of multiple matches, later matches paint
 over earlier ones. This is only really relevant if you
 use look-around assertions that contain capture groups,
 which can allow a capture to highlight a region outside
 the part of the string matched by that iteration of the