hl(1)

HL(1) User Commands HL(1)

NAME

hl - Colorize strings matching regular expressions

VERSION

Version 1.174

SYNOPSIS

hl [-oO][-h|-H|-V|-[[%.]eiuvdDEL1234][-[rgybmcwRGYBMCWnAIsNpPxJTt] regexp ...][--config_name ...]

or :

hl regexp

with environment variable HL_DEFAULT initialized

DESCRIPTION

hl reads standard input and colorize strings matching regular expressions with specified colors.

OPTIONS

-o
usage will be displayed on stdout (default = stderr)
-O
debug messages will be displayed on stdout (default = stderr)
-h
display help message. When -v is specified before -h (or when using -vh), some examples are given and environment variables are displayed with their current and default values
-H
display help message and configuration names found in $HOME/.hl.cfg
-V
display version information and exit
-v
verbose
-u
does not bufferize output on stdout
-e
use extended regular expressions
-i
ignore case
-E
display on stderr every string matching the regular expression specified by the next command line color specifier
-r
display strings matching the associated regular expression in red
-g
display strings matching the associated regular expression in green
-y
display strings matching the associated regular expression in yellow
-b
display strings matching the associated regular expression in blue
-m
display strings matching the associated regular expression in magenta
-c
display strings matching the associated regular expression in cyan
-w
display strings matching the associated regular expression in white
-R
display strings matching the associated regular expression in red (reverse video)
-G
display strings matching the associated regular expression in green (reverse video)
-Y
display strings matching the associated regular expression in yellow (reverse video)
-B
display strings matching the associated regular expression in blue (reverse video)
-M
display strings matching the associated regular expression in magenta (reverse video)
-C
display strings matching the associated regular expression in cyan (reverse video)
-W
display strings matching the associated regular expression in white (reverse video)
-n
display strings matching the associated regular expression uncolorized
-%c
Specifies the beginning of a range colorized in color 'c'.
-.
Specifies the end of the range colorized in color 'c'.
-d
activate debug
-D
display specified regular expressions
-L
lex debug
-1
color brightness (half bright). Changes the brightness of all the following colors, until another brightness is specified.
-2
color brightness (normal : default). Changes the brightness of all the following colors, until another brightness is specified.
-3
color brightness (bright). Changes the brightness of all the following colors, until another brightness is specified.
-4
color brightness (underscore). Changes the brightness of all the following colors, until another brightness is specified.
-5
color brightness (blink, on some terminals).
-A
Specifies parameters to alternate colors when matching string changes.
-I
Specifies parameters to alternate colors when matching string stays identical.
Syntax for alternate options : -{A|I}[[s],c1c2...cn]
where s is a number from 0 to 9 indicating the selection regexp number, and c1, c2, ... cn are color specifiers to use
The following syntax : -{A|I}#a:s1,c11c12...c1n:c21c22..c2p

may be used to select a second color set in case there is a change detected by this -A (or -I) option but not by another -A (or -I) option whose number is given by #a.
(See example 11 for more explanation).

Alternate colors implies extended regular expressions (-e)

-a
Specify parameters to alternate colors at each match on a line.
Syntax for alternate options : -a[[s],c1c2...cn]
where s is a number from 0 to 9 indicating the selection regexp number, and c1, c2, ... cn are color specifiers to use
-s
Alternate colors when the string matched by the selection regex is the image by a simple function (+, -, * or /) of the value of the previous matching string
Syntax for sequential control option : -s[[-+*/]p[adox]:][n],c1c2...cn]
where p is a positive integer (parameter), n is a number from 0 to 9 indicating the selection regexp number, and c1, c2, ... cn are color specifiers to use
d : decimal (default)
o : octal
x : hexadecimal
a : ascii (first character of the matching string) Alternate colors implies extended regular expressions (-e)
-J
Colorize date according to the day of the week

Syntax for day of week option : -J[Ys1ms2ds3[,c1c2...c7]]
where :
s1 : number of the sub-regex for the year
s2 : number of the sub-regex for the month
s3 : number of the sub-regex for the day of the month and c1c2...c7 are the optional color specifiers for Sunday to Saturday
-T
Colorize string according to specified thresholds values

Syntax for thresholds option : -Ts[x],s1[:c1],s2[:c2]...s10[:c10]
where :
s is a number from 0 to 9 indicating the selection regexp number,
x indicates that thresholds are in hexadecimal
si : value of the i-th threshold for 1 <= i <= 10
c1 : color of the i-th range for 1 <= i <= 10
-t
Colorize string according to time periods

Syntax for time periods option : -tp[0][R][:num][:spec][,c1c2...c10]
where :
p is a time period specifier in [YmwdHMSun]
with the following meaning :
Y : year
m : month
w : week
d : day
H : hour
M : minute
S : second
u : micro-second
n : nano-second
0 tells that the date must be framed at the beginning of the period
R is an optional flag telling to use an optional time reference
instead of the current time. The optional time reference must be
specified before the regex argument
num is an optional number of time periods (default is 1)
spec is a string specifying the position of date elements,
composed of letters in [YmbdHMSus], each one followed by the
number of the sub-regex it is associated to,
with the following meaning :
Y : year
m : month
b : abbreviated month name
w : week
d : day
H : hour
M : minute
S : second
u : micro-second
n : nano-second
and c1c2...c7 are the optional color specifiers for the time periods

PRIORITIES

A color specifier always has a higher priority than the one that follows. As an example, the following command :

echo abababab | hl -r 'a' -g 'ab'

will colorize each "a" in red and each "b" in green, while the following one :

echo abababab | hl -g 'ab' -r 'a'

will colorize each letter in green.

PARENTHESIS

If no parenthesis are specified in the regular expression, then all characters matching the regexp will be colorized. If parenthesis are specified, only characters captured in the parenthesis will be colorized.

ENVIRONMENT VARIABLES

HL_DEFAULT
hl can be used to quickly highlight strings matching a regular expression with a default color. The environment variable HL_DEFAULT may be defined and initialized with a valid color specifier, such as "g", "2r" or "3Y".
HL_CONF
may contain a list or directory pathnames in which configurations files may be found. The pathnames are separated by a column (':'), like in PATH.
HL_CONF_GLOB
may contain a list of globbing expressions specifying patterns for configurations filenames. Expressions are separated by a column (':').
HL_DOW_SPEC
may contain a specifier for the specification of a date. Used with -J option, for colorizing the day of the week.
HL_DOW_REGEX
may contain a regex for the specification of a date. Used with HL_DOW_SPEC.
HL_TIME_REGEX_Y
may contain a regex for the specification of the year.
HL_TIME_REGEX_m
may contain a regex for the specification of the numerical month (plus year).
HL_TIME_REGEX_d
may contain a regex for the specification of the day (plus year and month).
HL_TIME_REGEX_H
may contain a regex for the specification of the hour of the day (plus year, month and day).
HL_TIME_REGEX_M
may contain a regex for the specification of the minutes of the hour (plus year, month, day and hour).
HL_TIME_REGEX_S
may contain a regex for the specification of the seconds of the hour (plus year, month, day, hour and minutes).
HL_TIME_REGEX_u
may contain a regex for the specification of the microseconds (plus the date).
HL_TIME_REGEX_n
may contain a regex for the specification of the nanoseconds (plus the date).
HL_TIME_SPEC_Y
may contain a specifier for the year.
HL_TIME_SPEC_m
may contain a specifier for the month.
HL_TIME_SPEC_d
may contain a specifier for the day.
HL_TIME_SPEC_H
may contain a specifier for the hours.
HL_TIME_SPEC_M
may contain a specifier for the minutes.
HL_TIME_SPEC_S
may contain a specifier for the seconds.
HL_TIME_SPEC_u
may contain a specifier for the microseconds.
HL_TIME_SPEC_n
may contain a specifier for the nanoseconds.
HL_THRES_REGEX
may contain a regex for the selection of the numbers to colorize using -T option (thresholds).

HL_A1
may contain the default color specifier for the 1st color of the -A (or -I) option.
HL_A2
may contain the default color specifier for the 2nd color of the -A (or -I) option.

HL_SUNDAY
may contain the default color specifier for Sunday of the -J option.
HL_MONDAY
may contain the default color specifier for Monday of the -J option.
HL_TUESDAY
may contain the default color specifier for Tuesday of the -J option.
HL_WEDNESDAY
may contain the default color specifier for Wednesday of the -J option.
HL_THURSDAY
may contain the default color specifier for Thursday of the -J option.
HL_FRIDAY
may contain the default color specifier for Friday of the -J option.
HL_SATURDAY
may contain the default color specifier for Saturday of the -J option.

HL_TIME_0
may contain the default color specifier for period 0 of the -t option.
HL_TIME_1
may contain the default color specifier for period 1 of the -t option.
HL_TIME_2
may contain the default color specifier for period 2 of the -t option.
HL_TIME_3
may contain the default color specifier for period 3 of the -t option.
HL_TIME_4
may contain the default color specifier for period 4 of the -t option.
HL_TIME_5
may contain the default color specifier for period 5 of the -t option.
HL_TIME_6
may contain the default color specifier for period 6 of the -t option.
HL_TIME_7
may contain the default color specifier for period 7 of the -t option.
HL_TIME_8
may contain the default color specifier for period 8 of the -t option.
HL_TIME_9
may contain the default color specifier for period 9 of the -t option.

HL_T_2_1
may contain the default color specifier for the 1st of 2 ranges of the -T option.
HL_T_2_2
may contain the default color specifier for the 2nd of 2 ranges of the -T option.

HL_T_3_1
may contain the default color specifier for the 1st of 3 ranges of the -T option.
HL_T_3_2
may contain the default color specifier for the 2nd of 3 ranges of the -T option.
HL_T_3_3
may contain the default color specifier for the 3rd of 3 ranges of the -T option.

HL_T_4_1
may contain the default color specifier for the 1st of 4 ranges of the -T option.
HL_T_4_2
may contain the default color specifier for the 2nd of 4 ranges of the -T option.
HL_T_4_3
may contain the default color specifier for the 3rd of 4 ranges of the -T option.
HL_T_4_4
may contain the default color specifier for the 4th of 4 ranges of the -T option.

HL_T_5_1
may contain the default color specifier for the 1st of 5 ranges of the -T option.
HL_T_5_2
may contain the default color specifier for the 2nd of 5 ranges of the -T option.
HL_T_5_3
may contain the default color specifier for the 3rd of 5 ranges of the -T option.
HL_T_5_4
may contain the default color specifier for the 4th of 5 ranges of the -T option.
HL_T_5_5
may contain the default color specifier for the 5th of 5 ranges of the -T option.

HL_T_6_1
may contain the default color specifier for the 1st of 6 ranges of the -T option.
HL_T_6_2
may contain the default color specifier for the 2nd of 6 ranges of the -T option.
HL_T_6_3
may contain the default color specifier for the 3rd of 6 ranges of the -T option.
HL_T_6_4
may contain the default color specifier for the 4th of 6 ranges of the -T option.
HL_T_6_5
may contain the default color specifier for the 5th of 6 ranges of the -T option.
HL_T_6_6
may contain the default color specifier for the 6th of 6 ranges of the -T option.

HL_T_7_1
may contain the default color specifier for the 1st of 7 ranges of the -T option.
HL_T_7_2
may contain the default color specifier for the 2nd of 7 ranges of the -T option.
HL_T_7_3
may contain the default color specifier for the 3rd of 7 ranges of the -T option.
HL_T_7_4
may contain the default color specifier for the 4th of 7 ranges of the -T option.
HL_T_7_5
may contain the default color specifier for the 5th of 7 ranges of the -T option.
HL_T_7_6
may contain the default color specifier for the 6th of 7 ranges of the -T option.
HL_T_7_7
may contain the default color specifier for the 7th of 7 ranges of the -T option.

HL_T_8_1
may contain the default color specifier for the 1st of 8 ranges of the -T option.
HL_T_8_2
may contain the default color specifier for the 2nd of 8 ranges of the -T option.
HL_T_8_3
may contain the default color specifier for the 3rd of 8 ranges of the -T option.
HL_T_8_4
may contain the default color specifier for the 4th of 8 ranges of the -T option.
HL_T_8_5
may contain the default color specifier for the 5th of 8 ranges of the -T option.
HL_T_8_6
may contain the default color specifier for the 6th of 8 ranges of the -T option.
HL_T_8_7
may contain the default color specifier for the 7th of 8 ranges of the -T option.
HL_T_8_8
may contain the default color specifier for the 8th of 8 ranges of the -T option.

HL_T_9_1
may contain the default color specifier for the 1st of 9 ranges of the -T option.
HL_T_9_2
may contain the default color specifier for the 2nd of 9 ranges of the -T option.
HL_T_9_3
may contain the default color specifier for the 3rd of 9 ranges of the -T option.
HL_T_9_4
may contain the default color specifier for the 4th of 9 ranges of the -T option.
HL_T_9_5
may contain the default color specifier for the 5th of 9 ranges of the -T option.
HL_T_9_6
may contain the default color specifier for the 6th of 9 ranges of the -T option.
HL_T_9_7
may contain the default color specifier for the 7th of 9 ranges of the -T option.
HL_T_9_8
may contain the default color specifier for the 8th of 9 ranges of the -T option.
HL_T_9_9
may contain the default color specifier for the 9th of 9 ranges of the -T option.

HL_T_10_1
may contain the default color specifier for the 1st of 10 ranges of the -T option.
HL_T_10_2
may contain the default color specifier for the 2nd of 10 ranges of the -T option.
HL_T_10_3
may contain the default color specifier for the 3rd of 10 ranges of the -T option.
HL_T_10_4
may contain the default color specifier for the 4th of 10 ranges of the -T option.
HL_T_10_5
may contain the default color specifier for the 5th of 10 ranges of the -T option.
HL_T_10_6
may contain the default color specifier for the 6th of 10 ranges of the -T option.
HL_T_10_7
may contain the default color specifier for the 7th of 10 ranges of the -T option.
HL_T_10_8
may contain the default color specifier for the 8th of 10 ranges of the -T option.
HL_T_10_9
may contain the default color specifier for the 9th of 10 ranges of the -T option.
HL_T_10_10
may contain the default color specifier for the 10th of 10 ranges of the -T option.

HL_T_V_1
may contain the lower limit of the 1st range of the -T option
HL_T_V_2
may contain the lower limit of the 2nd range of the -T option
HL_T_V_3
may contain the lower limit of the 3rd range of the -T option
HL_T_V_4
may contain the lower limit of the 4th range of the -T option
HL_T_V_5
may contain the lower limit of the 5th range of the -T option
HL_T_V_6
may contain the lower limit of the 6th range of the -T option
HL_T_V_7
may contain the lower limit of the 7th range of the -T option
HL_T_V_8
may contain the lower limit of the 8th range of the -T option
HL_T_V_9
may contain the lower limit of the 9th range of the -T option
HL_T_V_10
may contain the lower limit of the 10th range of the -T option

EXAMPLES

Example 1 :
hl -ei -c '([0-9a-f]{2}:){5}[0-9a-f]{2}'

This command colorizes a MAC address in cyan.

Example 2 :
hl -e -g '<(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])>' -r '[0-9]'

This command colorizes a valid IP address in green and an invalid IP address in red, so that the following command :

hl -e -g '<(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])>' -r '[0-9]' <<-EOF

	192.168.266.1
	192.168.26.1
EOF
will display 192.168.266.1 in red and 192.168.26.1 in green.

Example 3 :
dpkg -l | hl -ei -Er '.*systemd>.*' -Eg '(.*(sysvinit|system-v-).*)' > /dev/null

On Debian, this command will list the packages whose description line contains strings containing the word "systemd" in red, and lines containing "sysvinit" or "system-v-" in green, whatever the case.

Example 4 :
/sbin/ifconfig -a | hl --ifconfig

Colorize the output of the ifconfig command according to the configuration ifconfig specified in the configuration file.

Example 5 :
df -h | hl --df

Colorize the output of the df command according to the configuration df specified in the configuration file.

Example 6 :
/sbin/ifconfig -a | hl --IP --MAC --eth

Colorize the output of the ifconfig command according to the configurations IP, MAC and eth specified in the configuration file.

Example 7 :
cal 2015 | hl -%3c 'January' -. '^$'

Colorize the output of the cal command with the first three month in bright cyan : from the word January to the first empty line.

Example 8 :
export HL_DEFAULT=3Y; ls -l / | hl lib

Specify that the default highlight color is '3Y' (high intensity yellow in reverse video), so that hl can be used with no color option but just one regular expression on the command line.

Example 9 :
cat logfile | hl -A1,3Y3c '(.*([12][0-9]{3}[-/][0-9]{2}[-/][0-9]{2}[ ]+..:..:..).*)'

Alternate the colors when the date (format = YYYY-mm-dd HH:MM:SS) changes. Selection regexp is regexp number 1. First color used (3Y) is high intensity yellow (reverse video) and second color (3c) is high intensity cyan. More than two colors may be specified with this option.

Example 10 :
export HL_A1=2G; export HL_A2=3b

Define default alternate colors in environment variables so that you can use -A or -I without specifing colors. Only two colors may be specified that way.

Example 11 :
cmd | hl -A0,2B3c '^[^ ]+ +([^ ]+) ' -A#1:0,2G3g:3r2R '^([^ ]+) ' -A#1:0,1B3b:3m3M '^[^ ]+ +[^ ]+ +([^ ]+)'

This set of options comes from the hl_tool script and it is intended to alternate the colors of the 2nd field with colors 2B and 3c, to alternate the colors of the 1st field with colors 2G and 3g, but if there is a change on the 1st field but not not the 2nd field, the color set to use is 3r and 2R. The change of the set is triggered by using the -A#1 string, where #1 denotes the number of the -A option which must be checked to decide whether to switch or not. In the same way, the 3rd -A option alternates the colors of the 3rd field with colors 1B and 3b, but in case of a change on the 3rd field and not on the 2nd field, the color set to use is 3m and 3M. This is achieved by using the syntax -A#1, just line the previous option. This extension of the -A option has been implemented to synchronize the color changes of fields 1 and 2 when using option -M of the hl_tool script, in order to make the result more readable.

FILES

Since version 1.57, the default configuration for hl is /etc/default/hl . This configuration file is common to all users.
But each user can define his own configurations in his own $HOME/.hl.cfg configuration file. Users' configurations have the precedence over default configurations.

Their recognized syntax is :

- comment lines (beginning with a '#'),

- configuration definition (a name, eventually followed by spaces or tabs, and a ':'),

- configuration options for this configuration (a tab, followed by the options)

- an empty line acts as a separator between configurations

Example :

#
#	Example of .hl.cfg configuration file
#	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
cal		:
	-e
	-g '[1-9][0-9][0-9][0-9]'
	-y 'January|February|March|April|May|June|July|August|September|October|November|December'
	-c 'Su|Mo|Tu|We|Th|Fr|Sa'
	-b '[0-9]'
df		:
	-e
	-r '<((100|9[5-9])%.*)'	
	-y '<((8[0-9]|9[0-4])%.*)'
	-c '<[0-4][0-9]?%.*'
	-g '<[0-9]+%.*'
	-b '^Filesystem.*'
diff		:
	-e
	-y '^<.*'
	-g '^>.*'
	-c '^([0-9]+(,[0-9]+)?[a-z][0-9]+(,[0-9]+)?)'
hl		:
	-ei
	-2B '^hl: version.*'
	-1g 'Usage'
	-2
	-R  ' +(.*<red>....).*reverse video.*'
	-G  ' +(.*<green>..).*reverse video.*'
	-Y  ' +(.*<yellow>.).*reverse video.*'
	-B  ' +(.*<blue>...).*reverse video.*'
	-M  ' +(.*<magenta>).*reverse video.*'
	-C  ' +(.*<cyan>...).*reverse video.*'
	-W  ' +(.*<white>..).*reverse video.*'
	-r  '.*<red>.*'
	-g  '.*<green>.*'
	-y  '.*<yellow>.*'
	-b  '.*<blue>.*'
	-m  '.*<magenta>.*'
	-c  '.*<cyan>.*'
	-w  '.*<white>.*'
    

SEE ALSO

hl(5)

MAN PAGE VERSION

The version of this man page is 1.20. It is compatible with hl version 1.174 and upper.

AUTHOR

The original version of this manual page was written by Martial Bornet <mbornet (.) pro (at) wanadoo (.) fr> for the GNU/Linux system.

The author also can be contacted with <man (.) flashnux (at) gmail (.) com>.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU GPL.

May 2025