How to have tail -f show colored output
I'd like to be able to tail the output of a server log file that has messages like:
INFO
SEVERE
etc, and if it's SEVERE
, show the line in red; if it's INFO
, in green. What kind of alias can I setup for a tail
command that would help me do this?
command-line colors alias highlighting tail
add a comment |
I'd like to be able to tail the output of a server log file that has messages like:
INFO
SEVERE
etc, and if it's SEVERE
, show the line in red; if it's INFO
, in green. What kind of alias can I setup for a tail
command that would help me do this?
command-line colors alias highlighting tail
one-linesed
: stackoverflow.com/a/14691971/52074
– Trevor Boyd Smith
Sep 14 '18 at 18:45
add a comment |
I'd like to be able to tail the output of a server log file that has messages like:
INFO
SEVERE
etc, and if it's SEVERE
, show the line in red; if it's INFO
, in green. What kind of alias can I setup for a tail
command that would help me do this?
command-line colors alias highlighting tail
I'd like to be able to tail the output of a server log file that has messages like:
INFO
SEVERE
etc, and if it's SEVERE
, show the line in red; if it's INFO
, in green. What kind of alias can I setup for a tail
command that would help me do this?
command-line colors alias highlighting tail
command-line colors alias highlighting tail
edited Mar 16 '11 at 21:51
Gilles
532k12810651592
532k12810651592
asked Mar 1 '11 at 19:13
Amir AfghaniAmir Afghani
2,27392020
2,27392020
one-linesed
: stackoverflow.com/a/14691971/52074
– Trevor Boyd Smith
Sep 14 '18 at 18:45
add a comment |
one-linesed
: stackoverflow.com/a/14691971/52074
– Trevor Boyd Smith
Sep 14 '18 at 18:45
one-line
sed
: stackoverflow.com/a/14691971/52074– Trevor Boyd Smith
Sep 14 '18 at 18:45
one-line
sed
: stackoverflow.com/a/14691971/52074– Trevor Boyd Smith
Sep 14 '18 at 18:45
add a comment |
19 Answers
19
active
oldest
votes
Try out multitail. This is an übergeneralization of tail -f
. You can watch multiple files in separate windows, highlight lines based on their content, and more.
multitail -c /path/to/log
The colors are configurable. If the default color scheme doesn't work for you, write your own in the config file. For example, call multitail -cS amir_log /path/to/log
with the following ~/.multitailrc
:
colorscheme:amir_log
cs_re:green:INFO
cs_re:red:SEVERE
Another solution, if you're on a server where it's inconvenient to install non-standard tools, is to combine tail -f
with sed or awk to add color selection control sequences. This requires tail -f
to flush its standard output without delay even when its standard output is a pipe, I don't know if all implementations do this.
tail -f /path/to/log | awk '
/INFO/ {print "33[32m" $0 "33[39m"}
/SEVERE/ {print "33[31m" $0 "33[39m"}
'
or with sed
tail -f /path/to/log | sed --unbuffered
-e 's/(.*INFO.*)/o033[32m1o033[39m/'
-e 's/(.*SEVERE.*)/o033[31m1o033[39m/'
If your sed isn't GNU sed, replace o033
by a literal escape character.
Yet another possibility is to run tail -f
in an Emacs shell buffer and use Emacs's syntax coloring abilities.
how can you do this withsed
? (sorry for being lazy and not figuring it out myself!) But would you please add ased
example as well.
– Ali
Nov 28 '11 at 16:41
4
@Ali Sed is less convenient because it doesn't have a syntax for the escape character, you need to have it literally in the script or use a shell quoting method to work it in. I recommend that you use awk.
– Gilles
Nov 28 '11 at 17:18
6
@Gilles In yourtail -f
withawk
code, if a string doesn't have INFO and SEVERE, the string isn't be printed. How can I print the remain strings either? (The string doesn't need to be colored)
– Benjamin
Jun 29 '12 at 10:32
5
@Benjamin Add; next
before the closing braces to skip further processing, and a new processing line1 {print}
at the end (1
means always).
– Gilles
Jun 29 '12 at 11:58
2
sed --unbuffered -e 's/(.*FATAL.*)/o033[1;31m1o033[0;39m/' -e 's/(.*ERROR.*)/o033[31m1o033[39m/' -e 's/(.*WARN.*)/o033[33m1o033[39m/' -e 's/(.*INFO.*)/o033[32m1o033[39m/' -e 's/(.*DEBUG.*)/o033[34m1o033[39m/' -e 's/(.*TRACE.*)/o033[30m1o033[39m/' -e 's/(.*[Ee]xception.*)/o033[1;39m1o033[0;39m/'
– DmitrySandalov
Sep 7 '18 at 15:07
|
show 7 more comments
grc, the generic colouriser is pretty cool.
Just do
grc tail -f /var/log/apache2/error.log
and enjoy!
You’ll also find it on GitHub.
2
This is exactly what I needed: lightweight and simple. The coloring isn't exactly right for my log types (custom logs) but any coloring makes it easier for me to follow a log.
– rennat
Oct 21 '11 at 19:49
For me 'grc' on Debian errors out with: OSError: [Errno 13] Permission denied. Also it depends on Python being installed so it's not relaly lightweight unless you already have it. I have found 'ccze' to work much better, ex. 'tail -f -n 50 /var/log/starbound-server.log | ccze -A'.
– Daniel Sokolowski
Dec 9 '13 at 3:56
1
grc default settings in Ubuntu didn't display nice for syslogs or mail.log. It is not easy to understand how to customize it.
– lepe
Jan 27 '14 at 3:34
1
I found it quicker and easier way to colorize than multitail. Just did a quick install via source on my CentOS system and upgraded my life. Will install on my other systems too.
– zeeshan
Jul 12 '14 at 9:51
3
This looks pretty terrible on nginx logs i.imgur.com/aJbIOfL.png
– mpen
Sep 3 '14 at 2:34
|
show 2 more comments
Have you had a look at ccze? You have the possibility to customize the default colors of some keywords using the option -c
or directly in your configuration file. If your screen is clearing after colorizing you must use option -A
.
Edit:
If you really would like to have the complete line colored in red, you could also have a try at the following:
$ tail -f myfile.log | perl -pe 's/.*SEVERE.*/e[1;31m$&e[0m/g'
e[1;31m
will give you the red color. If you would like some yellow, use e[1;33m
, and for green use e[1;32m
. The e[0m
restores the normal text color.
1
This doesn't work on Mac - I'm upvoting it because it works on Linux.
– Amir Afghani
Mar 1 '11 at 21:33
Upvoting because while the perl/ansi trick might not, ccze does.
– Shadur
Nov 13 '11 at 16:02
You can also make your terminal send an alert or "beep" by adding07
to the end of the regex, like so:perl -pe 's/(ERROR)/33[31m$133[0m07/g;'
. This works awesome if you are using tmux withset -g bell-action any
, in which case if you have your log tailing in another window, that window name will alert whenever the regex finds a match.
– jonyamo
Nov 13 '12 at 4:15
@AmirAfghani This is a linux/unix SE site, therefore I am not sure why you thought it would work on mac.
– BЈовић
Jun 4 '13 at 6:06
1
@BЈовић Mac is a Unix.
– Chris Down
Sep 12 '13 at 19:16
|
show 5 more comments
Have a look at lnav, the advanced log file viewer.
It can also pretty print various formats.
Before:
After:
add a comment |
You can use rainbow, which colorizes lines based on regular expressions:
rainbow --red='SEVERE.*' --green='INFO.*' tail -f my-file.log
It also comes bundled with predefined configs, for example for Tomcat logs:
rainbow --config=tomcat tail -f my-file.log
1
I tried most of the other solutions offered to this question, but rainbow was the only one that worked equally well on sun, aix, linux, termux, darwin, and cygwin -- the 6(!) environments I use on a daily basis. All the others involved difficult non-portable build processes for at least some platforms.
– Stabledog
May 17 '17 at 15:15
add a comment |
You can use colortail:
colortail -f /var/log/messages
2
+1 available at Ubuntu repositories. What I like of colortail compared to ccze is that you can customize freely your patterns using RegEx. Available colors: black, brightblack, white, brightwhite, magenta, brightmagenta, cyan, brightcyan, green,brightgreen, yellow, brightyellow, red,brightred, blue, brightblue. Unfortunately there is no way to set bold or other colors like orange.
– lepe
Jan 27 '14 at 3:55
I would like to correct one point about my previous comment: "bright"+color includes "bold" (some colors will actually look brighter as well)
– lepe
Jan 27 '14 at 4:25
add a comment |
Also note that if you just want to look for one matching regex, GNU grep with --color
will work — just pipe your tail
output through that.
The OP only wanted to highlight the output, not filter it. Grep won't show non-matching lines...
– Coderer
Jun 30 '14 at 12:36
3
If you saygrep -A9999 -B9999
regex
, it will show all lines unless you have 10,000 non-matching lines in a row. Use something likeGREP_COLORS="ms=31:sl=33:cx=32" grep -A9999 -B9999 SEVERE
to show the wordSEVERE
in red, the rest of SEVERE lines in yellow, and all other (non-SEVERE) lines (up to 9999) in green.
– G-Man
Aug 7 '15 at 2:45
You might need to pass--color=always
to grep instead of just--color
, depending on the order of your pipe, but yes, this works tail (GNU coreutils) 8.27 installed on my box.
– Hank Schultz
Jul 2 '18 at 15:26
add a comment |
I quite like colorex. Simple, yet satisfying.
tail -f /var/log/syslog | colorex -G '[0-9]{2}:[0-9]{2}:[0-9]{2}' -b $(hostname)
9
how is that simple?
– Eliran Malka
Apr 13 '15 at 10:40
add a comment |
To get colored output from standard commands like grep
, you should set this alias
in your .bashrc
# User specific aliases and functions
alias grep='grep --color=auto'
when you grep something in your file you see something like this, (but probably in red):
[root@linuxbox mydir]# grep "(INFO|SEVERE)" /var/log/logname
this entry is an INFO
SEVERE this entry is a warn!
this entry is an INFO
this entry is an INFO
SEVERE this entry is a warn!
if want to use tail
or awk
and want that the color survive to a pipe, then the alias is not enough and you should use the --color=always
parameter, for example:
[root@linubox mydir]# grep --color=always "(INFO|SEVERE)" /var/log/logname | tail -f | awk '{ print $1 }'
this
SEVERE
this
this
SEVERE
If you want color text with awk
the story is a little bit complex but more powerfull, for example:
[root@linubox mydir]# tail -f /var/log/messages | awk '{if ($5 ~ /INFO/) print "33[1;32m"$0"33[0m"; else if ($1 ~ /SEVERE/) print "33[1;31m"$0"33[0m"; else print $0}'
this entry is an INFO
SEVERE this entry is a warn!
this is another ENTRY
this entry is an INFO
this is another ENTRY
this entry is an INFO
SEVERE this entry is a warn!
with each line in its own color.
There are many other way to get colorized text from shell with other tools and they are well descripted by other members.
add a comment |
Based on @uloBasEI answer, I've tried to use ... | perl ... | perl ...
, but Linux pipe gets a bit crazy and is too slow. If I put all rules in only one perl
command, it works fine.
For example, create a perl
file colorTail.pl as below:
#!/usr/bin/perl -w
while(<STDIN>) {
my $line = $_;
chomp($line);
for($line){
s/==>.*<==/e[1;44m$&e[0m/gi; #tail multiples files name in blue background
s/.*exception.*|at .*/e[0;31m$&e[0m/gi; #java errors & stacktraces in red
s/info.*/e[1;32m$&e[0m/gi; #info replacement in green
s/warning.*/e[1;33m$&e[0m/gi; #warning replacement in yellow
}
print $line, "n";
}
Use it as:
tail -f *.log | perl colorTail.pl
tail -f *.log -f **/*.log | perl colorTail.pl
NOTE: you can use it on MobaXTerm too! Just download perl
plug-in from MobaXTerm site.
add a comment |
tail -f /var/log/logname | source-highlight -f esc -s log
7
source-highlight
isn't a widely installed command, so you should at least give a link to the project site.
– Gilles
Mar 16 '11 at 22:45
Available in Fedora 19.
– sjas
Sep 29 '13 at 14:55
And Ubuntu 12.10.
– sjas
Sep 29 '13 at 15:10
It looks nice. Its a big package compared to others in this list (26MB). It supports a huge list of languages. It can be customized modifying the config files located at: /usr/share/source-highlight/*.lang (Ubuntu). If you need something simple, go with ccze or colortail.
– lepe
Jan 27 '14 at 3:46
looks like it depends on boost, which is around 462MB
– ecsos
May 29 '14 at 21:34
add a comment |
One solution that works for coloring all sorts of text, not just logfiles, is a Python tool, 'colout'.
pip install colout
myprocess | colout REGEX_WITH_GROUPS color1,color2... [attr1,attr2...]
Where any text in the output of 'myprocess' which matches group 1 of the regex will be colored with color1, group 2 with color2, etc.
For example:
tail -f /var/log/mylogfile | colout '^(w+ d+ [d:]+)|(w+.py:d+ .+()): (.+)$' white,black,cyan bold,bold,normal
i.e. the first regex group (parens) matches the initial date in the logfile, the second group matches a python filename, line number and function name, and the third group matches the log message that comes after that. This looks like:
Note that lines or parts of lines which don't match any of my regex are still echoed, so this isn't like 'grep --color' - nothing is filtered out of the output.
Obviously this is flexible enough that you can use it with any process, not just tailing logfiles. I usually just whip up a new regex on the fly any time I want to colorize something. For this reason, I prefer colout to any custom logfile-coloring tool, because I only need to learn one tool, regardless of what I'm coloring: logging, test output, syntax highlighting snippets of code in the terminal, etc.
1
I haven’t seen a single answer that modified the source log file
– Dani_l
Dec 7 '17 at 15:38
@Dani_l Right you are! At the time I wrote this, I must have confused myself by flipping back and forth between this and a similar question, to which many of the answers were about how to configure logging such that the ANSI characters were written directly into the log file itself. I'll delete that complaint from my answer.
– Jonathan Hartley
Dec 7 '17 at 17:10
add a comment |
Shameless plug: I wrote a tool called TxtStyle that does something similar as the options mentioned earlier. You can run it as follows:
tail -f /var/log/syslog | txts --regex 'd+'
You can also define named styles in the config file (~/.txts.conf
) and use it like so:
ifconfig | txts --name ifconfig
(ifconfig
style is defined out of the box)
add a comment |
I wrote a bash function that accepts up to three parameters and does a grep-like filter on a text file, and outputs text to the screen in color.
I would also like to see a tail function that would do this, but haven't found one yet.
This function can also be improved - I'd appreciate any help on how to make it better.
function multigrep(){
#THIS WORKS - Recreate this, using input parameters
#sed -En '/(App)|(Spe)/p' ./flashlog.txt;
filename="/Users/stevewarren/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt";
paramString="";
for element in "$@"
do
#echo $element;
paramString="$paramString($element)|";
done
#TRIM FINAL | OFF PARAMSTRING
paramString=${paramString:0:${#paramString}-1};
#CREATE SED EXPRESSION - '/($1)|($2)|(...)/p'
paramString="'/$paramString/p'";
#CREATE SED FUNCTION, CALL ON FILE
paramString="sed -En $paramString ./flashlog.txt"
echo $paramString;
echo "${txtbld}$(tput setaf 7)" > ./flashlog_output.txt;
eval $paramString >> ./flashlog_output.txt;
echo >> ./flashlog_output.txt;
#cat ./flashlog_output.txt;
cat ./flashlog_output.txt | while read LINE
do
[[ $1 && ${1-x} ]] &&
if grep -q $1 <<<$LINE; then
echo "$(tput setaf 3)$LINE"
fi
[[ $2 && ${2-x} ]] &&
if grep -q $2 <<<$LINE; then
echo "$(tput setaf 7)$LINE"
fi
[[ $3 && ${3-x} ]] &&
if grep -q $3 <<<$LINE; then
echo "$(tput setaf 6)$LINE"
fi
done
}
add a comment |
sure !
I wrote long a go a function called "egrepi", based on the 8 color variables definitions.
This works ONLY piped like a "tail -f" colored function.
1. setColors
first, the color variables function to be called at first:
setColors ()
{
set -a
which printf >/dev/null 2>&1 && print=printf || print=print # Mandriva doesn't know about printf
hide='eval tput civis'
show='eval tput cnorm'
CLS=$(tput clear)
bel=$(tput bel)
case ${UNAME} in
AIX)
# text / foreground
N=$(${print} '33[1;30m')
n=$(${print} '33[0;30m')
R=$(${print} '33[1;31m')
r=$(${print} '33[0;31m')
G=$(${print} '33[1;32m')
g=$(${print} '33[0;32m')
Y=$(${print} '33[1;33m')
y=$(${print} '33[0;33m')
B=$(${print} '33[1;34m')
b=$(${print} '33[0;34m')
M=$(${print} '33[1;35m')
m=$(${print} '33[0;35m')
C=$(${print} '33[1;36m')
c=$(${print} '33[0;36m')
W=$(${print} '33[1;37m')
w=$(${print} '33[0;37m')
END=$(${print} '33[0m')
# background
RN=$(${print} '33[6;40m')
Rn=$(${print} '33[40m')
RR=$(${print} '33[6;41m')
Rr=$(${print} '33[41m')
RG=$(${print} '33[6;42m')
Rg=$(${print} '33[42m')
RY=$(${print} '33[6;43m')
Ry=$(${print} '33[43m')
RB=$(${print} '33[6;44m')
Rb=$(${print} '33[44m')
RM=$(${print} '33[6;45m')
Rm=$(${print} '33[45m')
RC=$(${print} '33[6;46m')
Rc=$(${print} '33[46m')
RW=$(${print} '33[6;47m')
Rw=$(${print} '33[47m')
HIGH=$(tput bold)
SMUL=$(tput smul)
RMUL=$(tput rmul)
BLINK=$(tput blink)
REVERSE=$(tput smso)
REVERSO=$(tput rmso)
;;
*)
# text / foreground
n=$(tput setaf 0)
r=$(tput setaf 1)
g=$(tput setaf 2)
y=$(tput setaf 3)
b=$(tput setaf 4)
m=$(tput setaf 5)
c=$(tput setaf 6)
w=$(tput setaf 7)
N=$(tput setaf 8)
R=$(tput setaf 9)
G=$(tput setaf 10)
Y=$(tput setaf 11)
B=$(tput setaf 12)
M=$(tput setaf 13)
C=$(tput setaf 14)
W=$(tput setaf 15)
END=$(tput sgr0)
HIGH=$(tput bold)
SMUL=$(tput smul)
RMUL=$(tput rmul)
BLINK=$(tput blink)
REVERSE=$(tput smso)
REVERSO=$(tput rmso)
# background
Rn=$(tput setab 0)
Rr=$(tput setab 1)
Rg=$(tput setab 2)
Ry=$(tput setab 3)
Rb=$(tput setab 4)
Rm=$(tput setab 5)
Rc=$(tput setab 6)
Rw=$(tput setab 7)
RN=$(tput setab 8)
RR=$(tput setab 9)
RG=$(tput setab 10)
RY=$(tput setab 11)
RB=$(tput setab 12)
RM=$(tput setab 13)
RC=$(tput setab 14)
RW=$(tput setab 15)
;;
esac
BLUEf=${B}
BLUE=${b}
REDf=${R}
RED=${r}
GREENf=${G}
GREEN=${g}
YELLOWf=${Y}
YELLOW=${y}
MANGENTAf=${M}
MANGENTA=${m}
WHITEf=${W}
WHITE=${w}
CYANf=${C}
CYAN=${c}
OK="${RG}${n}OK${END}"
KO="${RR}${n}KO${END}"
NA="${N}NA${END}"
COLORIZE='eval sed -e "s/{END}/${END}/g" -e "s/{HIGH}/${HIGH}/g" -e "s/{SMUL}/${SMUL}/g" -e "s/{RMUL}/${RMUL}/g" -e "s/{BLINK}/${BLINK}/g" -e "s/{REVERSE}/${REVERSE}/g" -e "s/{REVERSO}/${REVERSO}/g"'
LOWS=' -e "s/{n}/${n}/g" -e "s/{r}/${r}/g" -e "s/{g}/${g}/g" -e "s/{y}/${y}/g" -e "s/{b}/${b}/g" -e "s/{m}/${m}/g" -e "s/{c}/${c}/g" -e "s/{w}/${w}/g"'
HIGHS=' -e "s/{N}/${N}/g" -e "s/{R}/${R}/g" -e "s/{G}/${G}/g" -e "s/{Y}/${Y}/g" -e "s/{B}/${B}/g" -e "s/{M}/${M}/g" -e "s/{C}/${C}/g" -e "s/{W}/${W}/g"'
REVLOWS=' -e "s/{Rn}/${Rn}/g" -e "s/{Rr}/${Rr}/g" -e "s/{Rg}/${Rg}/g" -e "s/{Ry}/${Ry}/g" -e "s/{Rb}/${Rb}/g" -e "s/{Rm}/${Rm}/g" -e "s/{Rc}/${Rc}/g" -e "s/{Rw}/${Rw}/g"'
REVHIGHS=' -e "s/{RN}/${RN}/g" -e "s/{RR}/${RR}/g" -e "s/{RG}/${RG}/g" -e "s/{RY}/${RY}/g" -e "s/{RB}/${RB}/g" -e "s/{RM}/${RM}/g" -e "s/{RC}/${RC}/g" -e "s/{RW}/${RW}/g"'
# COLORIZE Usage:
# command |${COLORIZE} ${LOWS} ${HIGHS} ${REVLOWS} ${REVHIGHS}
set +a
}
2. egrepi
and the egrepi function, effective and elegant: color cycling between 8 or more colors (your needs) AND tested under 3 different unix OS, with comments :
# egrepi() egrep with 8 REVERSE cyclic colorations on regexps almost like egrep
# egrepi
# current script will work for KSH88, KSH93, bash 2+, zsh, under AIX / Linux / SunOS
egrepi ()
{
args=$*
# colorList=wBcgymrN # KSH93 or bash 3+, not for AIX
# set -A color # needed with older sh
color[0]=$Rw; color[1]=$RB; color[2]=$Rc; color[3]=$Rg; color[4]=$Ry; color[5]=$Rm; color[6]=$Rr; color[7]=$RN; # this is the only one AIX solution
i=0
unset argsToGrep argsSedColor argsPerlColor
for arg in ${args}
do
[ "${arg}" == "." ] && arg=\. # if you wanna grep "."
# color=R${colorList:((${RANDOM: -1:1})):1} # bash RANDOMized colors
# color=R${colorList:$i:1} && let i++ && ((i==8)) && i=0 # KSH93 or bash 3+, not for AIX
argsToGrep="${argsToGrep}${argsToGrep:+|}${arg}"
# argsSedColor="${argsSedColor} -e s#${arg}#$n${!color}&${w}#gI" # AIX KSH88 do not recognise this fucking variable double expansion
# argsSedColor="${argsSedColor} -e s#${arg}#$n${color[$i]}&${w}#gI" # AIX neither do include sed with Ignore case
argsPerlColor="${argsPerlColor}${argsPerlColor:+,}s#${arg}#$n${color[$i]}$&${END}#gi" # So: gotta use perl
let i+=1 && ((i==8)) && i=0 # AIX KSH88 do not recognise "let i++"
done
# egrep -i "${argsToGrep}" | sed ${argsSedColor} | egrep -v "grep|sed" # AIX sed incompatibility with Ignore case
# (($# > 0)) && (egrep -i "${argsToGrep}" | perl -p -e ${argsPerlColor}) || cat # this line colors & grep the words, will NOT act as "tail -f"
(($# > 0)) && (perl -p -e ${argsPerlColor}) || cat # this line just colors the words
}
3. Usage
command | egrepi word1 .. wordN
add a comment |
You might also want to take a look at lwatch:
tail -f /var/log/syslog | lwatch --input -
add a comment |
grc for sure!
customize your collors with regex in the file: ~.grc/conf.tail (or whatever name you want)
regexp=.*(select .*)$
colours=unchanged,cyan
=====
regexp=.*(update .*)$
colours=unchanged,bold yellow
=====
regexp=.*(insert .*)$
colours=unchanged,bold yellow
=====
regexp=.*(emp=d+).*
colours=unchanged,reverse green
=====
regexp=.*http.*/rest/contahub.cmds.(.*?)/(w*).*$
colours=unchanged,green,magenta
=====
regexp=.*http.*/M/.*.(.*?Facade)/(w*).*$
colours=unchanged,underline green,underline magenta
command line:
grc -c conf.tail tail -f log/tomcat/catalina.out
results:
info for configuring grc:
https://github.com/manjuraj/config/blob/master/.grc/sample.conf
add a comment |
As for the color codes, I would use tput:
red=$( tput -Txterm setaf 1 )
norm=$( tput -Txterm sgr0 )
bold=$( tput -Txterm bold )
See for reference: man tput
Then:
tail -F myfile.log | sed "s/(.ERROR.*)/$red$bold1$norm/g"
Great, thanks. Works like a charm with standard shell functions.
– vquintans
Jul 13 '18 at 8:56
add a comment |
Publishes some time ago Node Js utility - log-color-highlight
tail -f file | lch -red error warn -green success
lch -f file -red.bold error warn -underline.bgGreen success
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f8414%2fhow-to-have-tail-f-show-colored-output%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
19 Answers
19
active
oldest
votes
19 Answers
19
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try out multitail. This is an übergeneralization of tail -f
. You can watch multiple files in separate windows, highlight lines based on their content, and more.
multitail -c /path/to/log
The colors are configurable. If the default color scheme doesn't work for you, write your own in the config file. For example, call multitail -cS amir_log /path/to/log
with the following ~/.multitailrc
:
colorscheme:amir_log
cs_re:green:INFO
cs_re:red:SEVERE
Another solution, if you're on a server where it's inconvenient to install non-standard tools, is to combine tail -f
with sed or awk to add color selection control sequences. This requires tail -f
to flush its standard output without delay even when its standard output is a pipe, I don't know if all implementations do this.
tail -f /path/to/log | awk '
/INFO/ {print "33[32m" $0 "33[39m"}
/SEVERE/ {print "33[31m" $0 "33[39m"}
'
or with sed
tail -f /path/to/log | sed --unbuffered
-e 's/(.*INFO.*)/o033[32m1o033[39m/'
-e 's/(.*SEVERE.*)/o033[31m1o033[39m/'
If your sed isn't GNU sed, replace o033
by a literal escape character.
Yet another possibility is to run tail -f
in an Emacs shell buffer and use Emacs's syntax coloring abilities.
how can you do this withsed
? (sorry for being lazy and not figuring it out myself!) But would you please add ased
example as well.
– Ali
Nov 28 '11 at 16:41
4
@Ali Sed is less convenient because it doesn't have a syntax for the escape character, you need to have it literally in the script or use a shell quoting method to work it in. I recommend that you use awk.
– Gilles
Nov 28 '11 at 17:18
6
@Gilles In yourtail -f
withawk
code, if a string doesn't have INFO and SEVERE, the string isn't be printed. How can I print the remain strings either? (The string doesn't need to be colored)
– Benjamin
Jun 29 '12 at 10:32
5
@Benjamin Add; next
before the closing braces to skip further processing, and a new processing line1 {print}
at the end (1
means always).
– Gilles
Jun 29 '12 at 11:58
2
sed --unbuffered -e 's/(.*FATAL.*)/o033[1;31m1o033[0;39m/' -e 's/(.*ERROR.*)/o033[31m1o033[39m/' -e 's/(.*WARN.*)/o033[33m1o033[39m/' -e 's/(.*INFO.*)/o033[32m1o033[39m/' -e 's/(.*DEBUG.*)/o033[34m1o033[39m/' -e 's/(.*TRACE.*)/o033[30m1o033[39m/' -e 's/(.*[Ee]xception.*)/o033[1;39m1o033[0;39m/'
– DmitrySandalov
Sep 7 '18 at 15:07
|
show 7 more comments
Try out multitail. This is an übergeneralization of tail -f
. You can watch multiple files in separate windows, highlight lines based on their content, and more.
multitail -c /path/to/log
The colors are configurable. If the default color scheme doesn't work for you, write your own in the config file. For example, call multitail -cS amir_log /path/to/log
with the following ~/.multitailrc
:
colorscheme:amir_log
cs_re:green:INFO
cs_re:red:SEVERE
Another solution, if you're on a server where it's inconvenient to install non-standard tools, is to combine tail -f
with sed or awk to add color selection control sequences. This requires tail -f
to flush its standard output without delay even when its standard output is a pipe, I don't know if all implementations do this.
tail -f /path/to/log | awk '
/INFO/ {print "33[32m" $0 "33[39m"}
/SEVERE/ {print "33[31m" $0 "33[39m"}
'
or with sed
tail -f /path/to/log | sed --unbuffered
-e 's/(.*INFO.*)/o033[32m1o033[39m/'
-e 's/(.*SEVERE.*)/o033[31m1o033[39m/'
If your sed isn't GNU sed, replace o033
by a literal escape character.
Yet another possibility is to run tail -f
in an Emacs shell buffer and use Emacs's syntax coloring abilities.
how can you do this withsed
? (sorry for being lazy and not figuring it out myself!) But would you please add ased
example as well.
– Ali
Nov 28 '11 at 16:41
4
@Ali Sed is less convenient because it doesn't have a syntax for the escape character, you need to have it literally in the script or use a shell quoting method to work it in. I recommend that you use awk.
– Gilles
Nov 28 '11 at 17:18
6
@Gilles In yourtail -f
withawk
code, if a string doesn't have INFO and SEVERE, the string isn't be printed. How can I print the remain strings either? (The string doesn't need to be colored)
– Benjamin
Jun 29 '12 at 10:32
5
@Benjamin Add; next
before the closing braces to skip further processing, and a new processing line1 {print}
at the end (1
means always).
– Gilles
Jun 29 '12 at 11:58
2
sed --unbuffered -e 's/(.*FATAL.*)/o033[1;31m1o033[0;39m/' -e 's/(.*ERROR.*)/o033[31m1o033[39m/' -e 's/(.*WARN.*)/o033[33m1o033[39m/' -e 's/(.*INFO.*)/o033[32m1o033[39m/' -e 's/(.*DEBUG.*)/o033[34m1o033[39m/' -e 's/(.*TRACE.*)/o033[30m1o033[39m/' -e 's/(.*[Ee]xception.*)/o033[1;39m1o033[0;39m/'
– DmitrySandalov
Sep 7 '18 at 15:07
|
show 7 more comments
Try out multitail. This is an übergeneralization of tail -f
. You can watch multiple files in separate windows, highlight lines based on their content, and more.
multitail -c /path/to/log
The colors are configurable. If the default color scheme doesn't work for you, write your own in the config file. For example, call multitail -cS amir_log /path/to/log
with the following ~/.multitailrc
:
colorscheme:amir_log
cs_re:green:INFO
cs_re:red:SEVERE
Another solution, if you're on a server where it's inconvenient to install non-standard tools, is to combine tail -f
with sed or awk to add color selection control sequences. This requires tail -f
to flush its standard output without delay even when its standard output is a pipe, I don't know if all implementations do this.
tail -f /path/to/log | awk '
/INFO/ {print "33[32m" $0 "33[39m"}
/SEVERE/ {print "33[31m" $0 "33[39m"}
'
or with sed
tail -f /path/to/log | sed --unbuffered
-e 's/(.*INFO.*)/o033[32m1o033[39m/'
-e 's/(.*SEVERE.*)/o033[31m1o033[39m/'
If your sed isn't GNU sed, replace o033
by a literal escape character.
Yet another possibility is to run tail -f
in an Emacs shell buffer and use Emacs's syntax coloring abilities.
Try out multitail. This is an übergeneralization of tail -f
. You can watch multiple files in separate windows, highlight lines based on their content, and more.
multitail -c /path/to/log
The colors are configurable. If the default color scheme doesn't work for you, write your own in the config file. For example, call multitail -cS amir_log /path/to/log
with the following ~/.multitailrc
:
colorscheme:amir_log
cs_re:green:INFO
cs_re:red:SEVERE
Another solution, if you're on a server where it's inconvenient to install non-standard tools, is to combine tail -f
with sed or awk to add color selection control sequences. This requires tail -f
to flush its standard output without delay even when its standard output is a pipe, I don't know if all implementations do this.
tail -f /path/to/log | awk '
/INFO/ {print "33[32m" $0 "33[39m"}
/SEVERE/ {print "33[31m" $0 "33[39m"}
'
or with sed
tail -f /path/to/log | sed --unbuffered
-e 's/(.*INFO.*)/o033[32m1o033[39m/'
-e 's/(.*SEVERE.*)/o033[31m1o033[39m/'
If your sed isn't GNU sed, replace o033
by a literal escape character.
Yet another possibility is to run tail -f
in an Emacs shell buffer and use Emacs's syntax coloring abilities.
edited Dec 7 '17 at 15:15
Ondra Žižka
454311
454311
answered Mar 1 '11 at 20:29
GillesGilles
532k12810651592
532k12810651592
how can you do this withsed
? (sorry for being lazy and not figuring it out myself!) But would you please add ased
example as well.
– Ali
Nov 28 '11 at 16:41
4
@Ali Sed is less convenient because it doesn't have a syntax for the escape character, you need to have it literally in the script or use a shell quoting method to work it in. I recommend that you use awk.
– Gilles
Nov 28 '11 at 17:18
6
@Gilles In yourtail -f
withawk
code, if a string doesn't have INFO and SEVERE, the string isn't be printed. How can I print the remain strings either? (The string doesn't need to be colored)
– Benjamin
Jun 29 '12 at 10:32
5
@Benjamin Add; next
before the closing braces to skip further processing, and a new processing line1 {print}
at the end (1
means always).
– Gilles
Jun 29 '12 at 11:58
2
sed --unbuffered -e 's/(.*FATAL.*)/o033[1;31m1o033[0;39m/' -e 's/(.*ERROR.*)/o033[31m1o033[39m/' -e 's/(.*WARN.*)/o033[33m1o033[39m/' -e 's/(.*INFO.*)/o033[32m1o033[39m/' -e 's/(.*DEBUG.*)/o033[34m1o033[39m/' -e 's/(.*TRACE.*)/o033[30m1o033[39m/' -e 's/(.*[Ee]xception.*)/o033[1;39m1o033[0;39m/'
– DmitrySandalov
Sep 7 '18 at 15:07
|
show 7 more comments
how can you do this withsed
? (sorry for being lazy and not figuring it out myself!) But would you please add ased
example as well.
– Ali
Nov 28 '11 at 16:41
4
@Ali Sed is less convenient because it doesn't have a syntax for the escape character, you need to have it literally in the script or use a shell quoting method to work it in. I recommend that you use awk.
– Gilles
Nov 28 '11 at 17:18
6
@Gilles In yourtail -f
withawk
code, if a string doesn't have INFO and SEVERE, the string isn't be printed. How can I print the remain strings either? (The string doesn't need to be colored)
– Benjamin
Jun 29 '12 at 10:32
5
@Benjamin Add; next
before the closing braces to skip further processing, and a new processing line1 {print}
at the end (1
means always).
– Gilles
Jun 29 '12 at 11:58
2
sed --unbuffered -e 's/(.*FATAL.*)/o033[1;31m1o033[0;39m/' -e 's/(.*ERROR.*)/o033[31m1o033[39m/' -e 's/(.*WARN.*)/o033[33m1o033[39m/' -e 's/(.*INFO.*)/o033[32m1o033[39m/' -e 's/(.*DEBUG.*)/o033[34m1o033[39m/' -e 's/(.*TRACE.*)/o033[30m1o033[39m/' -e 's/(.*[Ee]xception.*)/o033[1;39m1o033[0;39m/'
– DmitrySandalov
Sep 7 '18 at 15:07
how can you do this with
sed
? (sorry for being lazy and not figuring it out myself!) But would you please add a sed
example as well.– Ali
Nov 28 '11 at 16:41
how can you do this with
sed
? (sorry for being lazy and not figuring it out myself!) But would you please add a sed
example as well.– Ali
Nov 28 '11 at 16:41
4
4
@Ali Sed is less convenient because it doesn't have a syntax for the escape character, you need to have it literally in the script or use a shell quoting method to work it in. I recommend that you use awk.
– Gilles
Nov 28 '11 at 17:18
@Ali Sed is less convenient because it doesn't have a syntax for the escape character, you need to have it literally in the script or use a shell quoting method to work it in. I recommend that you use awk.
– Gilles
Nov 28 '11 at 17:18
6
6
@Gilles In your
tail -f
with awk
code, if a string doesn't have INFO and SEVERE, the string isn't be printed. How can I print the remain strings either? (The string doesn't need to be colored)– Benjamin
Jun 29 '12 at 10:32
@Gilles In your
tail -f
with awk
code, if a string doesn't have INFO and SEVERE, the string isn't be printed. How can I print the remain strings either? (The string doesn't need to be colored)– Benjamin
Jun 29 '12 at 10:32
5
5
@Benjamin Add
; next
before the closing braces to skip further processing, and a new processing line 1 {print}
at the end (1
means always).– Gilles
Jun 29 '12 at 11:58
@Benjamin Add
; next
before the closing braces to skip further processing, and a new processing line 1 {print}
at the end (1
means always).– Gilles
Jun 29 '12 at 11:58
2
2
sed --unbuffered -e 's/(.*FATAL.*)/o033[1;31m1o033[0;39m/' -e 's/(.*ERROR.*)/o033[31m1o033[39m/' -e 's/(.*WARN.*)/o033[33m1o033[39m/' -e 's/(.*INFO.*)/o033[32m1o033[39m/' -e 's/(.*DEBUG.*)/o033[34m1o033[39m/' -e 's/(.*TRACE.*)/o033[30m1o033[39m/' -e 's/(.*[Ee]xception.*)/o033[1;39m1o033[0;39m/'
– DmitrySandalov
Sep 7 '18 at 15:07
sed --unbuffered -e 's/(.*FATAL.*)/o033[1;31m1o033[0;39m/' -e 's/(.*ERROR.*)/o033[31m1o033[39m/' -e 's/(.*WARN.*)/o033[33m1o033[39m/' -e 's/(.*INFO.*)/o033[32m1o033[39m/' -e 's/(.*DEBUG.*)/o033[34m1o033[39m/' -e 's/(.*TRACE.*)/o033[30m1o033[39m/' -e 's/(.*[Ee]xception.*)/o033[1;39m1o033[0;39m/'
– DmitrySandalov
Sep 7 '18 at 15:07
|
show 7 more comments
grc, the generic colouriser is pretty cool.
Just do
grc tail -f /var/log/apache2/error.log
and enjoy!
You’ll also find it on GitHub.
2
This is exactly what I needed: lightweight and simple. The coloring isn't exactly right for my log types (custom logs) but any coloring makes it easier for me to follow a log.
– rennat
Oct 21 '11 at 19:49
For me 'grc' on Debian errors out with: OSError: [Errno 13] Permission denied. Also it depends on Python being installed so it's not relaly lightweight unless you already have it. I have found 'ccze' to work much better, ex. 'tail -f -n 50 /var/log/starbound-server.log | ccze -A'.
– Daniel Sokolowski
Dec 9 '13 at 3:56
1
grc default settings in Ubuntu didn't display nice for syslogs or mail.log. It is not easy to understand how to customize it.
– lepe
Jan 27 '14 at 3:34
1
I found it quicker and easier way to colorize than multitail. Just did a quick install via source on my CentOS system and upgraded my life. Will install on my other systems too.
– zeeshan
Jul 12 '14 at 9:51
3
This looks pretty terrible on nginx logs i.imgur.com/aJbIOfL.png
– mpen
Sep 3 '14 at 2:34
|
show 2 more comments
grc, the generic colouriser is pretty cool.
Just do
grc tail -f /var/log/apache2/error.log
and enjoy!
You’ll also find it on GitHub.
2
This is exactly what I needed: lightweight and simple. The coloring isn't exactly right for my log types (custom logs) but any coloring makes it easier for me to follow a log.
– rennat
Oct 21 '11 at 19:49
For me 'grc' on Debian errors out with: OSError: [Errno 13] Permission denied. Also it depends on Python being installed so it's not relaly lightweight unless you already have it. I have found 'ccze' to work much better, ex. 'tail -f -n 50 /var/log/starbound-server.log | ccze -A'.
– Daniel Sokolowski
Dec 9 '13 at 3:56
1
grc default settings in Ubuntu didn't display nice for syslogs or mail.log. It is not easy to understand how to customize it.
– lepe
Jan 27 '14 at 3:34
1
I found it quicker and easier way to colorize than multitail. Just did a quick install via source on my CentOS system and upgraded my life. Will install on my other systems too.
– zeeshan
Jul 12 '14 at 9:51
3
This looks pretty terrible on nginx logs i.imgur.com/aJbIOfL.png
– mpen
Sep 3 '14 at 2:34
|
show 2 more comments
grc, the generic colouriser is pretty cool.
Just do
grc tail -f /var/log/apache2/error.log
and enjoy!
You’ll also find it on GitHub.
grc, the generic colouriser is pretty cool.
Just do
grc tail -f /var/log/apache2/error.log
and enjoy!
You’ll also find it on GitHub.
edited Dec 7 '17 at 14:12
Stephen Kitt
167k24376454
167k24376454
answered Oct 3 '11 at 14:57
thiasthias
1,2331107
1,2331107
2
This is exactly what I needed: lightweight and simple. The coloring isn't exactly right for my log types (custom logs) but any coloring makes it easier for me to follow a log.
– rennat
Oct 21 '11 at 19:49
For me 'grc' on Debian errors out with: OSError: [Errno 13] Permission denied. Also it depends on Python being installed so it's not relaly lightweight unless you already have it. I have found 'ccze' to work much better, ex. 'tail -f -n 50 /var/log/starbound-server.log | ccze -A'.
– Daniel Sokolowski
Dec 9 '13 at 3:56
1
grc default settings in Ubuntu didn't display nice for syslogs or mail.log. It is not easy to understand how to customize it.
– lepe
Jan 27 '14 at 3:34
1
I found it quicker and easier way to colorize than multitail. Just did a quick install via source on my CentOS system and upgraded my life. Will install on my other systems too.
– zeeshan
Jul 12 '14 at 9:51
3
This looks pretty terrible on nginx logs i.imgur.com/aJbIOfL.png
– mpen
Sep 3 '14 at 2:34
|
show 2 more comments
2
This is exactly what I needed: lightweight and simple. The coloring isn't exactly right for my log types (custom logs) but any coloring makes it easier for me to follow a log.
– rennat
Oct 21 '11 at 19:49
For me 'grc' on Debian errors out with: OSError: [Errno 13] Permission denied. Also it depends on Python being installed so it's not relaly lightweight unless you already have it. I have found 'ccze' to work much better, ex. 'tail -f -n 50 /var/log/starbound-server.log | ccze -A'.
– Daniel Sokolowski
Dec 9 '13 at 3:56
1
grc default settings in Ubuntu didn't display nice for syslogs or mail.log. It is not easy to understand how to customize it.
– lepe
Jan 27 '14 at 3:34
1
I found it quicker and easier way to colorize than multitail. Just did a quick install via source on my CentOS system and upgraded my life. Will install on my other systems too.
– zeeshan
Jul 12 '14 at 9:51
3
This looks pretty terrible on nginx logs i.imgur.com/aJbIOfL.png
– mpen
Sep 3 '14 at 2:34
2
2
This is exactly what I needed: lightweight and simple. The coloring isn't exactly right for my log types (custom logs) but any coloring makes it easier for me to follow a log.
– rennat
Oct 21 '11 at 19:49
This is exactly what I needed: lightweight and simple. The coloring isn't exactly right for my log types (custom logs) but any coloring makes it easier for me to follow a log.
– rennat
Oct 21 '11 at 19:49
For me 'grc' on Debian errors out with: OSError: [Errno 13] Permission denied. Also it depends on Python being installed so it's not relaly lightweight unless you already have it. I have found 'ccze' to work much better, ex. 'tail -f -n 50 /var/log/starbound-server.log | ccze -A'.
– Daniel Sokolowski
Dec 9 '13 at 3:56
For me 'grc' on Debian errors out with: OSError: [Errno 13] Permission denied. Also it depends on Python being installed so it's not relaly lightweight unless you already have it. I have found 'ccze' to work much better, ex. 'tail -f -n 50 /var/log/starbound-server.log | ccze -A'.
– Daniel Sokolowski
Dec 9 '13 at 3:56
1
1
grc default settings in Ubuntu didn't display nice for syslogs or mail.log. It is not easy to understand how to customize it.
– lepe
Jan 27 '14 at 3:34
grc default settings in Ubuntu didn't display nice for syslogs or mail.log. It is not easy to understand how to customize it.
– lepe
Jan 27 '14 at 3:34
1
1
I found it quicker and easier way to colorize than multitail. Just did a quick install via source on my CentOS system and upgraded my life. Will install on my other systems too.
– zeeshan
Jul 12 '14 at 9:51
I found it quicker and easier way to colorize than multitail. Just did a quick install via source on my CentOS system and upgraded my life. Will install on my other systems too.
– zeeshan
Jul 12 '14 at 9:51
3
3
This looks pretty terrible on nginx logs i.imgur.com/aJbIOfL.png
– mpen
Sep 3 '14 at 2:34
This looks pretty terrible on nginx logs i.imgur.com/aJbIOfL.png
– mpen
Sep 3 '14 at 2:34
|
show 2 more comments
Have you had a look at ccze? You have the possibility to customize the default colors of some keywords using the option -c
or directly in your configuration file. If your screen is clearing after colorizing you must use option -A
.
Edit:
If you really would like to have the complete line colored in red, you could also have a try at the following:
$ tail -f myfile.log | perl -pe 's/.*SEVERE.*/e[1;31m$&e[0m/g'
e[1;31m
will give you the red color. If you would like some yellow, use e[1;33m
, and for green use e[1;32m
. The e[0m
restores the normal text color.
1
This doesn't work on Mac - I'm upvoting it because it works on Linux.
– Amir Afghani
Mar 1 '11 at 21:33
Upvoting because while the perl/ansi trick might not, ccze does.
– Shadur
Nov 13 '11 at 16:02
You can also make your terminal send an alert or "beep" by adding07
to the end of the regex, like so:perl -pe 's/(ERROR)/33[31m$133[0m07/g;'
. This works awesome if you are using tmux withset -g bell-action any
, in which case if you have your log tailing in another window, that window name will alert whenever the regex finds a match.
– jonyamo
Nov 13 '12 at 4:15
@AmirAfghani This is a linux/unix SE site, therefore I am not sure why you thought it would work on mac.
– BЈовић
Jun 4 '13 at 6:06
1
@BЈовић Mac is a Unix.
– Chris Down
Sep 12 '13 at 19:16
|
show 5 more comments
Have you had a look at ccze? You have the possibility to customize the default colors of some keywords using the option -c
or directly in your configuration file. If your screen is clearing after colorizing you must use option -A
.
Edit:
If you really would like to have the complete line colored in red, you could also have a try at the following:
$ tail -f myfile.log | perl -pe 's/.*SEVERE.*/e[1;31m$&e[0m/g'
e[1;31m
will give you the red color. If you would like some yellow, use e[1;33m
, and for green use e[1;32m
. The e[0m
restores the normal text color.
1
This doesn't work on Mac - I'm upvoting it because it works on Linux.
– Amir Afghani
Mar 1 '11 at 21:33
Upvoting because while the perl/ansi trick might not, ccze does.
– Shadur
Nov 13 '11 at 16:02
You can also make your terminal send an alert or "beep" by adding07
to the end of the regex, like so:perl -pe 's/(ERROR)/33[31m$133[0m07/g;'
. This works awesome if you are using tmux withset -g bell-action any
, in which case if you have your log tailing in another window, that window name will alert whenever the regex finds a match.
– jonyamo
Nov 13 '12 at 4:15
@AmirAfghani This is a linux/unix SE site, therefore I am not sure why you thought it would work on mac.
– BЈовић
Jun 4 '13 at 6:06
1
@BЈовић Mac is a Unix.
– Chris Down
Sep 12 '13 at 19:16
|
show 5 more comments
Have you had a look at ccze? You have the possibility to customize the default colors of some keywords using the option -c
or directly in your configuration file. If your screen is clearing after colorizing you must use option -A
.
Edit:
If you really would like to have the complete line colored in red, you could also have a try at the following:
$ tail -f myfile.log | perl -pe 's/.*SEVERE.*/e[1;31m$&e[0m/g'
e[1;31m
will give you the red color. If you would like some yellow, use e[1;33m
, and for green use e[1;32m
. The e[0m
restores the normal text color.
Have you had a look at ccze? You have the possibility to customize the default colors of some keywords using the option -c
or directly in your configuration file. If your screen is clearing after colorizing you must use option -A
.
Edit:
If you really would like to have the complete line colored in red, you could also have a try at the following:
$ tail -f myfile.log | perl -pe 's/.*SEVERE.*/e[1;31m$&e[0m/g'
e[1;31m
will give you the red color. If you would like some yellow, use e[1;33m
, and for green use e[1;32m
. The e[0m
restores the normal text color.
edited Aug 6 '15 at 7:04
Daniel Sokolowski
1255
1255
answered Mar 1 '11 at 20:09
uloBasEIuloBasEI
2,01021518
2,01021518
1
This doesn't work on Mac - I'm upvoting it because it works on Linux.
– Amir Afghani
Mar 1 '11 at 21:33
Upvoting because while the perl/ansi trick might not, ccze does.
– Shadur
Nov 13 '11 at 16:02
You can also make your terminal send an alert or "beep" by adding07
to the end of the regex, like so:perl -pe 's/(ERROR)/33[31m$133[0m07/g;'
. This works awesome if you are using tmux withset -g bell-action any
, in which case if you have your log tailing in another window, that window name will alert whenever the regex finds a match.
– jonyamo
Nov 13 '12 at 4:15
@AmirAfghani This is a linux/unix SE site, therefore I am not sure why you thought it would work on mac.
– BЈовић
Jun 4 '13 at 6:06
1
@BЈовић Mac is a Unix.
– Chris Down
Sep 12 '13 at 19:16
|
show 5 more comments
1
This doesn't work on Mac - I'm upvoting it because it works on Linux.
– Amir Afghani
Mar 1 '11 at 21:33
Upvoting because while the perl/ansi trick might not, ccze does.
– Shadur
Nov 13 '11 at 16:02
You can also make your terminal send an alert or "beep" by adding07
to the end of the regex, like so:perl -pe 's/(ERROR)/33[31m$133[0m07/g;'
. This works awesome if you are using tmux withset -g bell-action any
, in which case if you have your log tailing in another window, that window name will alert whenever the regex finds a match.
– jonyamo
Nov 13 '12 at 4:15
@AmirAfghani This is a linux/unix SE site, therefore I am not sure why you thought it would work on mac.
– BЈовић
Jun 4 '13 at 6:06
1
@BЈовић Mac is a Unix.
– Chris Down
Sep 12 '13 at 19:16
1
1
This doesn't work on Mac - I'm upvoting it because it works on Linux.
– Amir Afghani
Mar 1 '11 at 21:33
This doesn't work on Mac - I'm upvoting it because it works on Linux.
– Amir Afghani
Mar 1 '11 at 21:33
Upvoting because while the perl/ansi trick might not, ccze does.
– Shadur
Nov 13 '11 at 16:02
Upvoting because while the perl/ansi trick might not, ccze does.
– Shadur
Nov 13 '11 at 16:02
You can also make your terminal send an alert or "beep" by adding
07
to the end of the regex, like so: perl -pe 's/(ERROR)/33[31m$133[0m07/g;'
. This works awesome if you are using tmux with set -g bell-action any
, in which case if you have your log tailing in another window, that window name will alert whenever the regex finds a match.– jonyamo
Nov 13 '12 at 4:15
You can also make your terminal send an alert or "beep" by adding
07
to the end of the regex, like so: perl -pe 's/(ERROR)/33[31m$133[0m07/g;'
. This works awesome if you are using tmux with set -g bell-action any
, in which case if you have your log tailing in another window, that window name will alert whenever the regex finds a match.– jonyamo
Nov 13 '12 at 4:15
@AmirAfghani This is a linux/unix SE site, therefore I am not sure why you thought it would work on mac.
– BЈовић
Jun 4 '13 at 6:06
@AmirAfghani This is a linux/unix SE site, therefore I am not sure why you thought it would work on mac.
– BЈовић
Jun 4 '13 at 6:06
1
1
@BЈовић Mac is a Unix.
– Chris Down
Sep 12 '13 at 19:16
@BЈовић Mac is a Unix.
– Chris Down
Sep 12 '13 at 19:16
|
show 5 more comments
Have a look at lnav, the advanced log file viewer.
It can also pretty print various formats.
Before:
After:
add a comment |
Have a look at lnav, the advanced log file viewer.
It can also pretty print various formats.
Before:
After:
add a comment |
Have a look at lnav, the advanced log file viewer.
It can also pretty print various formats.
Before:
After:
Have a look at lnav, the advanced log file viewer.
It can also pretty print various formats.
Before:
After:
edited Jul 14 '15 at 23:31
answered Feb 24 '15 at 14:46
bagonyibagonyi
40145
40145
add a comment |
add a comment |
You can use rainbow, which colorizes lines based on regular expressions:
rainbow --red='SEVERE.*' --green='INFO.*' tail -f my-file.log
It also comes bundled with predefined configs, for example for Tomcat logs:
rainbow --config=tomcat tail -f my-file.log
1
I tried most of the other solutions offered to this question, but rainbow was the only one that worked equally well on sun, aix, linux, termux, darwin, and cygwin -- the 6(!) environments I use on a daily basis. All the others involved difficult non-portable build processes for at least some platforms.
– Stabledog
May 17 '17 at 15:15
add a comment |
You can use rainbow, which colorizes lines based on regular expressions:
rainbow --red='SEVERE.*' --green='INFO.*' tail -f my-file.log
It also comes bundled with predefined configs, for example for Tomcat logs:
rainbow --config=tomcat tail -f my-file.log
1
I tried most of the other solutions offered to this question, but rainbow was the only one that worked equally well on sun, aix, linux, termux, darwin, and cygwin -- the 6(!) environments I use on a daily basis. All the others involved difficult non-portable build processes for at least some platforms.
– Stabledog
May 17 '17 at 15:15
add a comment |
You can use rainbow, which colorizes lines based on regular expressions:
rainbow --red='SEVERE.*' --green='INFO.*' tail -f my-file.log
It also comes bundled with predefined configs, for example for Tomcat logs:
rainbow --config=tomcat tail -f my-file.log
You can use rainbow, which colorizes lines based on regular expressions:
rainbow --red='SEVERE.*' --green='INFO.*' tail -f my-file.log
It also comes bundled with predefined configs, for example for Tomcat logs:
rainbow --config=tomcat tail -f my-file.log
edited May 23 '17 at 10:32
answered Mar 2 '11 at 22:28
nicoulajnicoulaj
36619
36619
1
I tried most of the other solutions offered to this question, but rainbow was the only one that worked equally well on sun, aix, linux, termux, darwin, and cygwin -- the 6(!) environments I use on a daily basis. All the others involved difficult non-portable build processes for at least some platforms.
– Stabledog
May 17 '17 at 15:15
add a comment |
1
I tried most of the other solutions offered to this question, but rainbow was the only one that worked equally well on sun, aix, linux, termux, darwin, and cygwin -- the 6(!) environments I use on a daily basis. All the others involved difficult non-portable build processes for at least some platforms.
– Stabledog
May 17 '17 at 15:15
1
1
I tried most of the other solutions offered to this question, but rainbow was the only one that worked equally well on sun, aix, linux, termux, darwin, and cygwin -- the 6(!) environments I use on a daily basis. All the others involved difficult non-portable build processes for at least some platforms.
– Stabledog
May 17 '17 at 15:15
I tried most of the other solutions offered to this question, but rainbow was the only one that worked equally well on sun, aix, linux, termux, darwin, and cygwin -- the 6(!) environments I use on a daily basis. All the others involved difficult non-portable build processes for at least some platforms.
– Stabledog
May 17 '17 at 15:15
add a comment |
You can use colortail:
colortail -f /var/log/messages
2
+1 available at Ubuntu repositories. What I like of colortail compared to ccze is that you can customize freely your patterns using RegEx. Available colors: black, brightblack, white, brightwhite, magenta, brightmagenta, cyan, brightcyan, green,brightgreen, yellow, brightyellow, red,brightred, blue, brightblue. Unfortunately there is no way to set bold or other colors like orange.
– lepe
Jan 27 '14 at 3:55
I would like to correct one point about my previous comment: "bright"+color includes "bold" (some colors will actually look brighter as well)
– lepe
Jan 27 '14 at 4:25
add a comment |
You can use colortail:
colortail -f /var/log/messages
2
+1 available at Ubuntu repositories. What I like of colortail compared to ccze is that you can customize freely your patterns using RegEx. Available colors: black, brightblack, white, brightwhite, magenta, brightmagenta, cyan, brightcyan, green,brightgreen, yellow, brightyellow, red,brightred, blue, brightblue. Unfortunately there is no way to set bold or other colors like orange.
– lepe
Jan 27 '14 at 3:55
I would like to correct one point about my previous comment: "bright"+color includes "bold" (some colors will actually look brighter as well)
– lepe
Jan 27 '14 at 4:25
add a comment |
You can use colortail:
colortail -f /var/log/messages
You can use colortail:
colortail -f /var/log/messages
edited Apr 13 '15 at 11:28
Eliran Malka
18018
18018
answered Apr 26 '13 at 6:16
Kartik MKartik M
28124
28124
2
+1 available at Ubuntu repositories. What I like of colortail compared to ccze is that you can customize freely your patterns using RegEx. Available colors: black, brightblack, white, brightwhite, magenta, brightmagenta, cyan, brightcyan, green,brightgreen, yellow, brightyellow, red,brightred, blue, brightblue. Unfortunately there is no way to set bold or other colors like orange.
– lepe
Jan 27 '14 at 3:55
I would like to correct one point about my previous comment: "bright"+color includes "bold" (some colors will actually look brighter as well)
– lepe
Jan 27 '14 at 4:25
add a comment |
2
+1 available at Ubuntu repositories. What I like of colortail compared to ccze is that you can customize freely your patterns using RegEx. Available colors: black, brightblack, white, brightwhite, magenta, brightmagenta, cyan, brightcyan, green,brightgreen, yellow, brightyellow, red,brightred, blue, brightblue. Unfortunately there is no way to set bold or other colors like orange.
– lepe
Jan 27 '14 at 3:55
I would like to correct one point about my previous comment: "bright"+color includes "bold" (some colors will actually look brighter as well)
– lepe
Jan 27 '14 at 4:25
2
2
+1 available at Ubuntu repositories. What I like of colortail compared to ccze is that you can customize freely your patterns using RegEx. Available colors: black, brightblack, white, brightwhite, magenta, brightmagenta, cyan, brightcyan, green,brightgreen, yellow, brightyellow, red,brightred, blue, brightblue. Unfortunately there is no way to set bold or other colors like orange.
– lepe
Jan 27 '14 at 3:55
+1 available at Ubuntu repositories. What I like of colortail compared to ccze is that you can customize freely your patterns using RegEx. Available colors: black, brightblack, white, brightwhite, magenta, brightmagenta, cyan, brightcyan, green,brightgreen, yellow, brightyellow, red,brightred, blue, brightblue. Unfortunately there is no way to set bold or other colors like orange.
– lepe
Jan 27 '14 at 3:55
I would like to correct one point about my previous comment: "bright"+color includes "bold" (some colors will actually look brighter as well)
– lepe
Jan 27 '14 at 4:25
I would like to correct one point about my previous comment: "bright"+color includes "bold" (some colors will actually look brighter as well)
– lepe
Jan 27 '14 at 4:25
add a comment |
Also note that if you just want to look for one matching regex, GNU grep with --color
will work — just pipe your tail
output through that.
The OP only wanted to highlight the output, not filter it. Grep won't show non-matching lines...
– Coderer
Jun 30 '14 at 12:36
3
If you saygrep -A9999 -B9999
regex
, it will show all lines unless you have 10,000 non-matching lines in a row. Use something likeGREP_COLORS="ms=31:sl=33:cx=32" grep -A9999 -B9999 SEVERE
to show the wordSEVERE
in red, the rest of SEVERE lines in yellow, and all other (non-SEVERE) lines (up to 9999) in green.
– G-Man
Aug 7 '15 at 2:45
You might need to pass--color=always
to grep instead of just--color
, depending on the order of your pipe, but yes, this works tail (GNU coreutils) 8.27 installed on my box.
– Hank Schultz
Jul 2 '18 at 15:26
add a comment |
Also note that if you just want to look for one matching regex, GNU grep with --color
will work — just pipe your tail
output through that.
The OP only wanted to highlight the output, not filter it. Grep won't show non-matching lines...
– Coderer
Jun 30 '14 at 12:36
3
If you saygrep -A9999 -B9999
regex
, it will show all lines unless you have 10,000 non-matching lines in a row. Use something likeGREP_COLORS="ms=31:sl=33:cx=32" grep -A9999 -B9999 SEVERE
to show the wordSEVERE
in red, the rest of SEVERE lines in yellow, and all other (non-SEVERE) lines (up to 9999) in green.
– G-Man
Aug 7 '15 at 2:45
You might need to pass--color=always
to grep instead of just--color
, depending on the order of your pipe, but yes, this works tail (GNU coreutils) 8.27 installed on my box.
– Hank Schultz
Jul 2 '18 at 15:26
add a comment |
Also note that if you just want to look for one matching regex, GNU grep with --color
will work — just pipe your tail
output through that.
Also note that if you just want to look for one matching regex, GNU grep with --color
will work — just pipe your tail
output through that.
answered Mar 16 '11 at 14:04
mattdmmattdm
28.4k1172112
28.4k1172112
The OP only wanted to highlight the output, not filter it. Grep won't show non-matching lines...
– Coderer
Jun 30 '14 at 12:36
3
If you saygrep -A9999 -B9999
regex
, it will show all lines unless you have 10,000 non-matching lines in a row. Use something likeGREP_COLORS="ms=31:sl=33:cx=32" grep -A9999 -B9999 SEVERE
to show the wordSEVERE
in red, the rest of SEVERE lines in yellow, and all other (non-SEVERE) lines (up to 9999) in green.
– G-Man
Aug 7 '15 at 2:45
You might need to pass--color=always
to grep instead of just--color
, depending on the order of your pipe, but yes, this works tail (GNU coreutils) 8.27 installed on my box.
– Hank Schultz
Jul 2 '18 at 15:26
add a comment |
The OP only wanted to highlight the output, not filter it. Grep won't show non-matching lines...
– Coderer
Jun 30 '14 at 12:36
3
If you saygrep -A9999 -B9999
regex
, it will show all lines unless you have 10,000 non-matching lines in a row. Use something likeGREP_COLORS="ms=31:sl=33:cx=32" grep -A9999 -B9999 SEVERE
to show the wordSEVERE
in red, the rest of SEVERE lines in yellow, and all other (non-SEVERE) lines (up to 9999) in green.
– G-Man
Aug 7 '15 at 2:45
You might need to pass--color=always
to grep instead of just--color
, depending on the order of your pipe, but yes, this works tail (GNU coreutils) 8.27 installed on my box.
– Hank Schultz
Jul 2 '18 at 15:26
The OP only wanted to highlight the output, not filter it. Grep won't show non-matching lines...
– Coderer
Jun 30 '14 at 12:36
The OP only wanted to highlight the output, not filter it. Grep won't show non-matching lines...
– Coderer
Jun 30 '14 at 12:36
3
3
If you say
grep -A9999 -B9999
regex
, it will show all lines unless you have 10,000 non-matching lines in a row. Use something like GREP_COLORS="ms=31:sl=33:cx=32" grep -A9999 -B9999 SEVERE
to show the word SEVERE
in red, the rest of SEVERE lines in yellow, and all other (non-SEVERE) lines (up to 9999) in green.– G-Man
Aug 7 '15 at 2:45
If you say
grep -A9999 -B9999
regex
, it will show all lines unless you have 10,000 non-matching lines in a row. Use something like GREP_COLORS="ms=31:sl=33:cx=32" grep -A9999 -B9999 SEVERE
to show the word SEVERE
in red, the rest of SEVERE lines in yellow, and all other (non-SEVERE) lines (up to 9999) in green.– G-Man
Aug 7 '15 at 2:45
You might need to pass
--color=always
to grep instead of just --color
, depending on the order of your pipe, but yes, this works tail (GNU coreutils) 8.27 installed on my box.– Hank Schultz
Jul 2 '18 at 15:26
You might need to pass
--color=always
to grep instead of just --color
, depending on the order of your pipe, but yes, this works tail (GNU coreutils) 8.27 installed on my box.– Hank Schultz
Jul 2 '18 at 15:26
add a comment |
I quite like colorex. Simple, yet satisfying.
tail -f /var/log/syslog | colorex -G '[0-9]{2}:[0-9]{2}:[0-9]{2}' -b $(hostname)
9
how is that simple?
– Eliran Malka
Apr 13 '15 at 10:40
add a comment |
I quite like colorex. Simple, yet satisfying.
tail -f /var/log/syslog | colorex -G '[0-9]{2}:[0-9]{2}:[0-9]{2}' -b $(hostname)
9
how is that simple?
– Eliran Malka
Apr 13 '15 at 10:40
add a comment |
I quite like colorex. Simple, yet satisfying.
tail -f /var/log/syslog | colorex -G '[0-9]{2}:[0-9]{2}:[0-9]{2}' -b $(hostname)
I quite like colorex. Simple, yet satisfying.
tail -f /var/log/syslog | colorex -G '[0-9]{2}:[0-9]{2}:[0-9]{2}' -b $(hostname)
answered Dec 18 '12 at 17:52
Brian M. HuntBrian M. Hunt
17113
17113
9
how is that simple?
– Eliran Malka
Apr 13 '15 at 10:40
add a comment |
9
how is that simple?
– Eliran Malka
Apr 13 '15 at 10:40
9
9
how is that simple?
– Eliran Malka
Apr 13 '15 at 10:40
how is that simple?
– Eliran Malka
Apr 13 '15 at 10:40
add a comment |
To get colored output from standard commands like grep
, you should set this alias
in your .bashrc
# User specific aliases and functions
alias grep='grep --color=auto'
when you grep something in your file you see something like this, (but probably in red):
[root@linuxbox mydir]# grep "(INFO|SEVERE)" /var/log/logname
this entry is an INFO
SEVERE this entry is a warn!
this entry is an INFO
this entry is an INFO
SEVERE this entry is a warn!
if want to use tail
or awk
and want that the color survive to a pipe, then the alias is not enough and you should use the --color=always
parameter, for example:
[root@linubox mydir]# grep --color=always "(INFO|SEVERE)" /var/log/logname | tail -f | awk '{ print $1 }'
this
SEVERE
this
this
SEVERE
If you want color text with awk
the story is a little bit complex but more powerfull, for example:
[root@linubox mydir]# tail -f /var/log/messages | awk '{if ($5 ~ /INFO/) print "33[1;32m"$0"33[0m"; else if ($1 ~ /SEVERE/) print "33[1;31m"$0"33[0m"; else print $0}'
this entry is an INFO
SEVERE this entry is a warn!
this is another ENTRY
this entry is an INFO
this is another ENTRY
this entry is an INFO
SEVERE this entry is a warn!
with each line in its own color.
There are many other way to get colorized text from shell with other tools and they are well descripted by other members.
add a comment |
To get colored output from standard commands like grep
, you should set this alias
in your .bashrc
# User specific aliases and functions
alias grep='grep --color=auto'
when you grep something in your file you see something like this, (but probably in red):
[root@linuxbox mydir]# grep "(INFO|SEVERE)" /var/log/logname
this entry is an INFO
SEVERE this entry is a warn!
this entry is an INFO
this entry is an INFO
SEVERE this entry is a warn!
if want to use tail
or awk
and want that the color survive to a pipe, then the alias is not enough and you should use the --color=always
parameter, for example:
[root@linubox mydir]# grep --color=always "(INFO|SEVERE)" /var/log/logname | tail -f | awk '{ print $1 }'
this
SEVERE
this
this
SEVERE
If you want color text with awk
the story is a little bit complex but more powerfull, for example:
[root@linubox mydir]# tail -f /var/log/messages | awk '{if ($5 ~ /INFO/) print "33[1;32m"$0"33[0m"; else if ($1 ~ /SEVERE/) print "33[1;31m"$0"33[0m"; else print $0}'
this entry is an INFO
SEVERE this entry is a warn!
this is another ENTRY
this entry is an INFO
this is another ENTRY
this entry is an INFO
SEVERE this entry is a warn!
with each line in its own color.
There are many other way to get colorized text from shell with other tools and they are well descripted by other members.
add a comment |
To get colored output from standard commands like grep
, you should set this alias
in your .bashrc
# User specific aliases and functions
alias grep='grep --color=auto'
when you grep something in your file you see something like this, (but probably in red):
[root@linuxbox mydir]# grep "(INFO|SEVERE)" /var/log/logname
this entry is an INFO
SEVERE this entry is a warn!
this entry is an INFO
this entry is an INFO
SEVERE this entry is a warn!
if want to use tail
or awk
and want that the color survive to a pipe, then the alias is not enough and you should use the --color=always
parameter, for example:
[root@linubox mydir]# grep --color=always "(INFO|SEVERE)" /var/log/logname | tail -f | awk '{ print $1 }'
this
SEVERE
this
this
SEVERE
If you want color text with awk
the story is a little bit complex but more powerfull, for example:
[root@linubox mydir]# tail -f /var/log/messages | awk '{if ($5 ~ /INFO/) print "33[1;32m"$0"33[0m"; else if ($1 ~ /SEVERE/) print "33[1;31m"$0"33[0m"; else print $0}'
this entry is an INFO
SEVERE this entry is a warn!
this is another ENTRY
this entry is an INFO
this is another ENTRY
this entry is an INFO
SEVERE this entry is a warn!
with each line in its own color.
There are many other way to get colorized text from shell with other tools and they are well descripted by other members.
To get colored output from standard commands like grep
, you should set this alias
in your .bashrc
# User specific aliases and functions
alias grep='grep --color=auto'
when you grep something in your file you see something like this, (but probably in red):
[root@linuxbox mydir]# grep "(INFO|SEVERE)" /var/log/logname
this entry is an INFO
SEVERE this entry is a warn!
this entry is an INFO
this entry is an INFO
SEVERE this entry is a warn!
if want to use tail
or awk
and want that the color survive to a pipe, then the alias is not enough and you should use the --color=always
parameter, for example:
[root@linubox mydir]# grep --color=always "(INFO|SEVERE)" /var/log/logname | tail -f | awk '{ print $1 }'
this
SEVERE
this
this
SEVERE
If you want color text with awk
the story is a little bit complex but more powerfull, for example:
[root@linubox mydir]# tail -f /var/log/messages | awk '{if ($5 ~ /INFO/) print "33[1;32m"$0"33[0m"; else if ($1 ~ /SEVERE/) print "33[1;31m"$0"33[0m"; else print $0}'
this entry is an INFO
SEVERE this entry is a warn!
this is another ENTRY
this entry is an INFO
this is another ENTRY
this entry is an INFO
SEVERE this entry is a warn!
with each line in its own color.
There are many other way to get colorized text from shell with other tools and they are well descripted by other members.
answered Aug 3 '12 at 15:57
tombolinuxtombolinux
34727
34727
add a comment |
add a comment |
Based on @uloBasEI answer, I've tried to use ... | perl ... | perl ...
, but Linux pipe gets a bit crazy and is too slow. If I put all rules in only one perl
command, it works fine.
For example, create a perl
file colorTail.pl as below:
#!/usr/bin/perl -w
while(<STDIN>) {
my $line = $_;
chomp($line);
for($line){
s/==>.*<==/e[1;44m$&e[0m/gi; #tail multiples files name in blue background
s/.*exception.*|at .*/e[0;31m$&e[0m/gi; #java errors & stacktraces in red
s/info.*/e[1;32m$&e[0m/gi; #info replacement in green
s/warning.*/e[1;33m$&e[0m/gi; #warning replacement in yellow
}
print $line, "n";
}
Use it as:
tail -f *.log | perl colorTail.pl
tail -f *.log -f **/*.log | perl colorTail.pl
NOTE: you can use it on MobaXTerm too! Just download perl
plug-in from MobaXTerm site.
add a comment |
Based on @uloBasEI answer, I've tried to use ... | perl ... | perl ...
, but Linux pipe gets a bit crazy and is too slow. If I put all rules in only one perl
command, it works fine.
For example, create a perl
file colorTail.pl as below:
#!/usr/bin/perl -w
while(<STDIN>) {
my $line = $_;
chomp($line);
for($line){
s/==>.*<==/e[1;44m$&e[0m/gi; #tail multiples files name in blue background
s/.*exception.*|at .*/e[0;31m$&e[0m/gi; #java errors & stacktraces in red
s/info.*/e[1;32m$&e[0m/gi; #info replacement in green
s/warning.*/e[1;33m$&e[0m/gi; #warning replacement in yellow
}
print $line, "n";
}
Use it as:
tail -f *.log | perl colorTail.pl
tail -f *.log -f **/*.log | perl colorTail.pl
NOTE: you can use it on MobaXTerm too! Just download perl
plug-in from MobaXTerm site.
add a comment |
Based on @uloBasEI answer, I've tried to use ... | perl ... | perl ...
, but Linux pipe gets a bit crazy and is too slow. If I put all rules in only one perl
command, it works fine.
For example, create a perl
file colorTail.pl as below:
#!/usr/bin/perl -w
while(<STDIN>) {
my $line = $_;
chomp($line);
for($line){
s/==>.*<==/e[1;44m$&e[0m/gi; #tail multiples files name in blue background
s/.*exception.*|at .*/e[0;31m$&e[0m/gi; #java errors & stacktraces in red
s/info.*/e[1;32m$&e[0m/gi; #info replacement in green
s/warning.*/e[1;33m$&e[0m/gi; #warning replacement in yellow
}
print $line, "n";
}
Use it as:
tail -f *.log | perl colorTail.pl
tail -f *.log -f **/*.log | perl colorTail.pl
NOTE: you can use it on MobaXTerm too! Just download perl
plug-in from MobaXTerm site.
Based on @uloBasEI answer, I've tried to use ... | perl ... | perl ...
, but Linux pipe gets a bit crazy and is too slow. If I put all rules in only one perl
command, it works fine.
For example, create a perl
file colorTail.pl as below:
#!/usr/bin/perl -w
while(<STDIN>) {
my $line = $_;
chomp($line);
for($line){
s/==>.*<==/e[1;44m$&e[0m/gi; #tail multiples files name in blue background
s/.*exception.*|at .*/e[0;31m$&e[0m/gi; #java errors & stacktraces in red
s/info.*/e[1;32m$&e[0m/gi; #info replacement in green
s/warning.*/e[1;33m$&e[0m/gi; #warning replacement in yellow
}
print $line, "n";
}
Use it as:
tail -f *.log | perl colorTail.pl
tail -f *.log -f **/*.log | perl colorTail.pl
NOTE: you can use it on MobaXTerm too! Just download perl
plug-in from MobaXTerm site.
edited Jul 10 '14 at 13:41
Ramesh
23.3k32101182
23.3k32101182
answered Jul 10 '14 at 13:08
surfealokeseasurfealokesea
15112
15112
add a comment |
add a comment |
tail -f /var/log/logname | source-highlight -f esc -s log
7
source-highlight
isn't a widely installed command, so you should at least give a link to the project site.
– Gilles
Mar 16 '11 at 22:45
Available in Fedora 19.
– sjas
Sep 29 '13 at 14:55
And Ubuntu 12.10.
– sjas
Sep 29 '13 at 15:10
It looks nice. Its a big package compared to others in this list (26MB). It supports a huge list of languages. It can be customized modifying the config files located at: /usr/share/source-highlight/*.lang (Ubuntu). If you need something simple, go with ccze or colortail.
– lepe
Jan 27 '14 at 3:46
looks like it depends on boost, which is around 462MB
– ecsos
May 29 '14 at 21:34
add a comment |
tail -f /var/log/logname | source-highlight -f esc -s log
7
source-highlight
isn't a widely installed command, so you should at least give a link to the project site.
– Gilles
Mar 16 '11 at 22:45
Available in Fedora 19.
– sjas
Sep 29 '13 at 14:55
And Ubuntu 12.10.
– sjas
Sep 29 '13 at 15:10
It looks nice. Its a big package compared to others in this list (26MB). It supports a huge list of languages. It can be customized modifying the config files located at: /usr/share/source-highlight/*.lang (Ubuntu). If you need something simple, go with ccze or colortail.
– lepe
Jan 27 '14 at 3:46
looks like it depends on boost, which is around 462MB
– ecsos
May 29 '14 at 21:34
add a comment |
tail -f /var/log/logname | source-highlight -f esc -s log
tail -f /var/log/logname | source-highlight -f esc -s log
answered Mar 16 '11 at 11:56
user5771
7
source-highlight
isn't a widely installed command, so you should at least give a link to the project site.
– Gilles
Mar 16 '11 at 22:45
Available in Fedora 19.
– sjas
Sep 29 '13 at 14:55
And Ubuntu 12.10.
– sjas
Sep 29 '13 at 15:10
It looks nice. Its a big package compared to others in this list (26MB). It supports a huge list of languages. It can be customized modifying the config files located at: /usr/share/source-highlight/*.lang (Ubuntu). If you need something simple, go with ccze or colortail.
– lepe
Jan 27 '14 at 3:46
looks like it depends on boost, which is around 462MB
– ecsos
May 29 '14 at 21:34
add a comment |
7
source-highlight
isn't a widely installed command, so you should at least give a link to the project site.
– Gilles
Mar 16 '11 at 22:45
Available in Fedora 19.
– sjas
Sep 29 '13 at 14:55
And Ubuntu 12.10.
– sjas
Sep 29 '13 at 15:10
It looks nice. Its a big package compared to others in this list (26MB). It supports a huge list of languages. It can be customized modifying the config files located at: /usr/share/source-highlight/*.lang (Ubuntu). If you need something simple, go with ccze or colortail.
– lepe
Jan 27 '14 at 3:46
looks like it depends on boost, which is around 462MB
– ecsos
May 29 '14 at 21:34
7
7
source-highlight
isn't a widely installed command, so you should at least give a link to the project site.– Gilles
Mar 16 '11 at 22:45
source-highlight
isn't a widely installed command, so you should at least give a link to the project site.– Gilles
Mar 16 '11 at 22:45
Available in Fedora 19.
– sjas
Sep 29 '13 at 14:55
Available in Fedora 19.
– sjas
Sep 29 '13 at 14:55
And Ubuntu 12.10.
– sjas
Sep 29 '13 at 15:10
And Ubuntu 12.10.
– sjas
Sep 29 '13 at 15:10
It looks nice. Its a big package compared to others in this list (26MB). It supports a huge list of languages. It can be customized modifying the config files located at: /usr/share/source-highlight/*.lang (Ubuntu). If you need something simple, go with ccze or colortail.
– lepe
Jan 27 '14 at 3:46
It looks nice. Its a big package compared to others in this list (26MB). It supports a huge list of languages. It can be customized modifying the config files located at: /usr/share/source-highlight/*.lang (Ubuntu). If you need something simple, go with ccze or colortail.
– lepe
Jan 27 '14 at 3:46
looks like it depends on boost, which is around 462MB
– ecsos
May 29 '14 at 21:34
looks like it depends on boost, which is around 462MB
– ecsos
May 29 '14 at 21:34
add a comment |
One solution that works for coloring all sorts of text, not just logfiles, is a Python tool, 'colout'.
pip install colout
myprocess | colout REGEX_WITH_GROUPS color1,color2... [attr1,attr2...]
Where any text in the output of 'myprocess' which matches group 1 of the regex will be colored with color1, group 2 with color2, etc.
For example:
tail -f /var/log/mylogfile | colout '^(w+ d+ [d:]+)|(w+.py:d+ .+()): (.+)$' white,black,cyan bold,bold,normal
i.e. the first regex group (parens) matches the initial date in the logfile, the second group matches a python filename, line number and function name, and the third group matches the log message that comes after that. This looks like:
Note that lines or parts of lines which don't match any of my regex are still echoed, so this isn't like 'grep --color' - nothing is filtered out of the output.
Obviously this is flexible enough that you can use it with any process, not just tailing logfiles. I usually just whip up a new regex on the fly any time I want to colorize something. For this reason, I prefer colout to any custom logfile-coloring tool, because I only need to learn one tool, regardless of what I'm coloring: logging, test output, syntax highlighting snippets of code in the terminal, etc.
1
I haven’t seen a single answer that modified the source log file
– Dani_l
Dec 7 '17 at 15:38
@Dani_l Right you are! At the time I wrote this, I must have confused myself by flipping back and forth between this and a similar question, to which many of the answers were about how to configure logging such that the ANSI characters were written directly into the log file itself. I'll delete that complaint from my answer.
– Jonathan Hartley
Dec 7 '17 at 17:10
add a comment |
One solution that works for coloring all sorts of text, not just logfiles, is a Python tool, 'colout'.
pip install colout
myprocess | colout REGEX_WITH_GROUPS color1,color2... [attr1,attr2...]
Where any text in the output of 'myprocess' which matches group 1 of the regex will be colored with color1, group 2 with color2, etc.
For example:
tail -f /var/log/mylogfile | colout '^(w+ d+ [d:]+)|(w+.py:d+ .+()): (.+)$' white,black,cyan bold,bold,normal
i.e. the first regex group (parens) matches the initial date in the logfile, the second group matches a python filename, line number and function name, and the third group matches the log message that comes after that. This looks like:
Note that lines or parts of lines which don't match any of my regex are still echoed, so this isn't like 'grep --color' - nothing is filtered out of the output.
Obviously this is flexible enough that you can use it with any process, not just tailing logfiles. I usually just whip up a new regex on the fly any time I want to colorize something. For this reason, I prefer colout to any custom logfile-coloring tool, because I only need to learn one tool, regardless of what I'm coloring: logging, test output, syntax highlighting snippets of code in the terminal, etc.
1
I haven’t seen a single answer that modified the source log file
– Dani_l
Dec 7 '17 at 15:38
@Dani_l Right you are! At the time I wrote this, I must have confused myself by flipping back and forth between this and a similar question, to which many of the answers were about how to configure logging such that the ANSI characters were written directly into the log file itself. I'll delete that complaint from my answer.
– Jonathan Hartley
Dec 7 '17 at 17:10
add a comment |
One solution that works for coloring all sorts of text, not just logfiles, is a Python tool, 'colout'.
pip install colout
myprocess | colout REGEX_WITH_GROUPS color1,color2... [attr1,attr2...]
Where any text in the output of 'myprocess' which matches group 1 of the regex will be colored with color1, group 2 with color2, etc.
For example:
tail -f /var/log/mylogfile | colout '^(w+ d+ [d:]+)|(w+.py:d+ .+()): (.+)$' white,black,cyan bold,bold,normal
i.e. the first regex group (parens) matches the initial date in the logfile, the second group matches a python filename, line number and function name, and the third group matches the log message that comes after that. This looks like:
Note that lines or parts of lines which don't match any of my regex are still echoed, so this isn't like 'grep --color' - nothing is filtered out of the output.
Obviously this is flexible enough that you can use it with any process, not just tailing logfiles. I usually just whip up a new regex on the fly any time I want to colorize something. For this reason, I prefer colout to any custom logfile-coloring tool, because I only need to learn one tool, regardless of what I'm coloring: logging, test output, syntax highlighting snippets of code in the terminal, etc.
One solution that works for coloring all sorts of text, not just logfiles, is a Python tool, 'colout'.
pip install colout
myprocess | colout REGEX_WITH_GROUPS color1,color2... [attr1,attr2...]
Where any text in the output of 'myprocess' which matches group 1 of the regex will be colored with color1, group 2 with color2, etc.
For example:
tail -f /var/log/mylogfile | colout '^(w+ d+ [d:]+)|(w+.py:d+ .+()): (.+)$' white,black,cyan bold,bold,normal
i.e. the first regex group (parens) matches the initial date in the logfile, the second group matches a python filename, line number and function name, and the third group matches the log message that comes after that. This looks like:
Note that lines or parts of lines which don't match any of my regex are still echoed, so this isn't like 'grep --color' - nothing is filtered out of the output.
Obviously this is flexible enough that you can use it with any process, not just tailing logfiles. I usually just whip up a new regex on the fly any time I want to colorize something. For this reason, I prefer colout to any custom logfile-coloring tool, because I only need to learn one tool, regardless of what I'm coloring: logging, test output, syntax highlighting snippets of code in the terminal, etc.
edited Dec 7 '17 at 17:12
answered Aug 19 '15 at 10:44
Jonathan HartleyJonathan Hartley
21317
21317
1
I haven’t seen a single answer that modified the source log file
– Dani_l
Dec 7 '17 at 15:38
@Dani_l Right you are! At the time I wrote this, I must have confused myself by flipping back and forth between this and a similar question, to which many of the answers were about how to configure logging such that the ANSI characters were written directly into the log file itself. I'll delete that complaint from my answer.
– Jonathan Hartley
Dec 7 '17 at 17:10
add a comment |
1
I haven’t seen a single answer that modified the source log file
– Dani_l
Dec 7 '17 at 15:38
@Dani_l Right you are! At the time I wrote this, I must have confused myself by flipping back and forth between this and a similar question, to which many of the answers were about how to configure logging such that the ANSI characters were written directly into the log file itself. I'll delete that complaint from my answer.
– Jonathan Hartley
Dec 7 '17 at 17:10
1
1
I haven’t seen a single answer that modified the source log file
– Dani_l
Dec 7 '17 at 15:38
I haven’t seen a single answer that modified the source log file
– Dani_l
Dec 7 '17 at 15:38
@Dani_l Right you are! At the time I wrote this, I must have confused myself by flipping back and forth between this and a similar question, to which many of the answers were about how to configure logging such that the ANSI characters were written directly into the log file itself. I'll delete that complaint from my answer.
– Jonathan Hartley
Dec 7 '17 at 17:10
@Dani_l Right you are! At the time I wrote this, I must have confused myself by flipping back and forth between this and a similar question, to which many of the answers were about how to configure logging such that the ANSI characters were written directly into the log file itself. I'll delete that complaint from my answer.
– Jonathan Hartley
Dec 7 '17 at 17:10
add a comment |
Shameless plug: I wrote a tool called TxtStyle that does something similar as the options mentioned earlier. You can run it as follows:
tail -f /var/log/syslog | txts --regex 'd+'
You can also define named styles in the config file (~/.txts.conf
) and use it like so:
ifconfig | txts --name ifconfig
(ifconfig
style is defined out of the box)
add a comment |
Shameless plug: I wrote a tool called TxtStyle that does something similar as the options mentioned earlier. You can run it as follows:
tail -f /var/log/syslog | txts --regex 'd+'
You can also define named styles in the config file (~/.txts.conf
) and use it like so:
ifconfig | txts --name ifconfig
(ifconfig
style is defined out of the box)
add a comment |
Shameless plug: I wrote a tool called TxtStyle that does something similar as the options mentioned earlier. You can run it as follows:
tail -f /var/log/syslog | txts --regex 'd+'
You can also define named styles in the config file (~/.txts.conf
) and use it like so:
ifconfig | txts --name ifconfig
(ifconfig
style is defined out of the box)
Shameless plug: I wrote a tool called TxtStyle that does something similar as the options mentioned earlier. You can run it as follows:
tail -f /var/log/syslog | txts --regex 'd+'
You can also define named styles in the config file (~/.txts.conf
) and use it like so:
ifconfig | txts --name ifconfig
(ifconfig
style is defined out of the box)
answered Feb 4 '13 at 20:51
armandinoarmandino
1212
1212
add a comment |
add a comment |
I wrote a bash function that accepts up to three parameters and does a grep-like filter on a text file, and outputs text to the screen in color.
I would also like to see a tail function that would do this, but haven't found one yet.
This function can also be improved - I'd appreciate any help on how to make it better.
function multigrep(){
#THIS WORKS - Recreate this, using input parameters
#sed -En '/(App)|(Spe)/p' ./flashlog.txt;
filename="/Users/stevewarren/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt";
paramString="";
for element in "$@"
do
#echo $element;
paramString="$paramString($element)|";
done
#TRIM FINAL | OFF PARAMSTRING
paramString=${paramString:0:${#paramString}-1};
#CREATE SED EXPRESSION - '/($1)|($2)|(...)/p'
paramString="'/$paramString/p'";
#CREATE SED FUNCTION, CALL ON FILE
paramString="sed -En $paramString ./flashlog.txt"
echo $paramString;
echo "${txtbld}$(tput setaf 7)" > ./flashlog_output.txt;
eval $paramString >> ./flashlog_output.txt;
echo >> ./flashlog_output.txt;
#cat ./flashlog_output.txt;
cat ./flashlog_output.txt | while read LINE
do
[[ $1 && ${1-x} ]] &&
if grep -q $1 <<<$LINE; then
echo "$(tput setaf 3)$LINE"
fi
[[ $2 && ${2-x} ]] &&
if grep -q $2 <<<$LINE; then
echo "$(tput setaf 7)$LINE"
fi
[[ $3 && ${3-x} ]] &&
if grep -q $3 <<<$LINE; then
echo "$(tput setaf 6)$LINE"
fi
done
}
add a comment |
I wrote a bash function that accepts up to three parameters and does a grep-like filter on a text file, and outputs text to the screen in color.
I would also like to see a tail function that would do this, but haven't found one yet.
This function can also be improved - I'd appreciate any help on how to make it better.
function multigrep(){
#THIS WORKS - Recreate this, using input parameters
#sed -En '/(App)|(Spe)/p' ./flashlog.txt;
filename="/Users/stevewarren/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt";
paramString="";
for element in "$@"
do
#echo $element;
paramString="$paramString($element)|";
done
#TRIM FINAL | OFF PARAMSTRING
paramString=${paramString:0:${#paramString}-1};
#CREATE SED EXPRESSION - '/($1)|($2)|(...)/p'
paramString="'/$paramString/p'";
#CREATE SED FUNCTION, CALL ON FILE
paramString="sed -En $paramString ./flashlog.txt"
echo $paramString;
echo "${txtbld}$(tput setaf 7)" > ./flashlog_output.txt;
eval $paramString >> ./flashlog_output.txt;
echo >> ./flashlog_output.txt;
#cat ./flashlog_output.txt;
cat ./flashlog_output.txt | while read LINE
do
[[ $1 && ${1-x} ]] &&
if grep -q $1 <<<$LINE; then
echo "$(tput setaf 3)$LINE"
fi
[[ $2 && ${2-x} ]] &&
if grep -q $2 <<<$LINE; then
echo "$(tput setaf 7)$LINE"
fi
[[ $3 && ${3-x} ]] &&
if grep -q $3 <<<$LINE; then
echo "$(tput setaf 6)$LINE"
fi
done
}
add a comment |
I wrote a bash function that accepts up to three parameters and does a grep-like filter on a text file, and outputs text to the screen in color.
I would also like to see a tail function that would do this, but haven't found one yet.
This function can also be improved - I'd appreciate any help on how to make it better.
function multigrep(){
#THIS WORKS - Recreate this, using input parameters
#sed -En '/(App)|(Spe)/p' ./flashlog.txt;
filename="/Users/stevewarren/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt";
paramString="";
for element in "$@"
do
#echo $element;
paramString="$paramString($element)|";
done
#TRIM FINAL | OFF PARAMSTRING
paramString=${paramString:0:${#paramString}-1};
#CREATE SED EXPRESSION - '/($1)|($2)|(...)/p'
paramString="'/$paramString/p'";
#CREATE SED FUNCTION, CALL ON FILE
paramString="sed -En $paramString ./flashlog.txt"
echo $paramString;
echo "${txtbld}$(tput setaf 7)" > ./flashlog_output.txt;
eval $paramString >> ./flashlog_output.txt;
echo >> ./flashlog_output.txt;
#cat ./flashlog_output.txt;
cat ./flashlog_output.txt | while read LINE
do
[[ $1 && ${1-x} ]] &&
if grep -q $1 <<<$LINE; then
echo "$(tput setaf 3)$LINE"
fi
[[ $2 && ${2-x} ]] &&
if grep -q $2 <<<$LINE; then
echo "$(tput setaf 7)$LINE"
fi
[[ $3 && ${3-x} ]] &&
if grep -q $3 <<<$LINE; then
echo "$(tput setaf 6)$LINE"
fi
done
}
I wrote a bash function that accepts up to three parameters and does a grep-like filter on a text file, and outputs text to the screen in color.
I would also like to see a tail function that would do this, but haven't found one yet.
This function can also be improved - I'd appreciate any help on how to make it better.
function multigrep(){
#THIS WORKS - Recreate this, using input parameters
#sed -En '/(App)|(Spe)/p' ./flashlog.txt;
filename="/Users/stevewarren/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt";
paramString="";
for element in "$@"
do
#echo $element;
paramString="$paramString($element)|";
done
#TRIM FINAL | OFF PARAMSTRING
paramString=${paramString:0:${#paramString}-1};
#CREATE SED EXPRESSION - '/($1)|($2)|(...)/p'
paramString="'/$paramString/p'";
#CREATE SED FUNCTION, CALL ON FILE
paramString="sed -En $paramString ./flashlog.txt"
echo $paramString;
echo "${txtbld}$(tput setaf 7)" > ./flashlog_output.txt;
eval $paramString >> ./flashlog_output.txt;
echo >> ./flashlog_output.txt;
#cat ./flashlog_output.txt;
cat ./flashlog_output.txt | while read LINE
do
[[ $1 && ${1-x} ]] &&
if grep -q $1 <<<$LINE; then
echo "$(tput setaf 3)$LINE"
fi
[[ $2 && ${2-x} ]] &&
if grep -q $2 <<<$LINE; then
echo "$(tput setaf 7)$LINE"
fi
[[ $3 && ${3-x} ]] &&
if grep -q $3 <<<$LINE; then
echo "$(tput setaf 6)$LINE"
fi
done
}
answered Mar 4 '13 at 20:43
Steve WarrenSteve Warren
112
112
add a comment |
add a comment |
sure !
I wrote long a go a function called "egrepi", based on the 8 color variables definitions.
This works ONLY piped like a "tail -f" colored function.
1. setColors
first, the color variables function to be called at first:
setColors ()
{
set -a
which printf >/dev/null 2>&1 && print=printf || print=print # Mandriva doesn't know about printf
hide='eval tput civis'
show='eval tput cnorm'
CLS=$(tput clear)
bel=$(tput bel)
case ${UNAME} in
AIX)
# text / foreground
N=$(${print} '33[1;30m')
n=$(${print} '33[0;30m')
R=$(${print} '33[1;31m')
r=$(${print} '33[0;31m')
G=$(${print} '33[1;32m')
g=$(${print} '33[0;32m')
Y=$(${print} '33[1;33m')
y=$(${print} '33[0;33m')
B=$(${print} '33[1;34m')
b=$(${print} '33[0;34m')
M=$(${print} '33[1;35m')
m=$(${print} '33[0;35m')
C=$(${print} '33[1;36m')
c=$(${print} '33[0;36m')
W=$(${print} '33[1;37m')
w=$(${print} '33[0;37m')
END=$(${print} '33[0m')
# background
RN=$(${print} '33[6;40m')
Rn=$(${print} '33[40m')
RR=$(${print} '33[6;41m')
Rr=$(${print} '33[41m')
RG=$(${print} '33[6;42m')
Rg=$(${print} '33[42m')
RY=$(${print} '33[6;43m')
Ry=$(${print} '33[43m')
RB=$(${print} '33[6;44m')
Rb=$(${print} '33[44m')
RM=$(${print} '33[6;45m')
Rm=$(${print} '33[45m')
RC=$(${print} '33[6;46m')
Rc=$(${print} '33[46m')
RW=$(${print} '33[6;47m')
Rw=$(${print} '33[47m')
HIGH=$(tput bold)
SMUL=$(tput smul)
RMUL=$(tput rmul)
BLINK=$(tput blink)
REVERSE=$(tput smso)
REVERSO=$(tput rmso)
;;
*)
# text / foreground
n=$(tput setaf 0)
r=$(tput setaf 1)
g=$(tput setaf 2)
y=$(tput setaf 3)
b=$(tput setaf 4)
m=$(tput setaf 5)
c=$(tput setaf 6)
w=$(tput setaf 7)
N=$(tput setaf 8)
R=$(tput setaf 9)
G=$(tput setaf 10)
Y=$(tput setaf 11)
B=$(tput setaf 12)
M=$(tput setaf 13)
C=$(tput setaf 14)
W=$(tput setaf 15)
END=$(tput sgr0)
HIGH=$(tput bold)
SMUL=$(tput smul)
RMUL=$(tput rmul)
BLINK=$(tput blink)
REVERSE=$(tput smso)
REVERSO=$(tput rmso)
# background
Rn=$(tput setab 0)
Rr=$(tput setab 1)
Rg=$(tput setab 2)
Ry=$(tput setab 3)
Rb=$(tput setab 4)
Rm=$(tput setab 5)
Rc=$(tput setab 6)
Rw=$(tput setab 7)
RN=$(tput setab 8)
RR=$(tput setab 9)
RG=$(tput setab 10)
RY=$(tput setab 11)
RB=$(tput setab 12)
RM=$(tput setab 13)
RC=$(tput setab 14)
RW=$(tput setab 15)
;;
esac
BLUEf=${B}
BLUE=${b}
REDf=${R}
RED=${r}
GREENf=${G}
GREEN=${g}
YELLOWf=${Y}
YELLOW=${y}
MANGENTAf=${M}
MANGENTA=${m}
WHITEf=${W}
WHITE=${w}
CYANf=${C}
CYAN=${c}
OK="${RG}${n}OK${END}"
KO="${RR}${n}KO${END}"
NA="${N}NA${END}"
COLORIZE='eval sed -e "s/{END}/${END}/g" -e "s/{HIGH}/${HIGH}/g" -e "s/{SMUL}/${SMUL}/g" -e "s/{RMUL}/${RMUL}/g" -e "s/{BLINK}/${BLINK}/g" -e "s/{REVERSE}/${REVERSE}/g" -e "s/{REVERSO}/${REVERSO}/g"'
LOWS=' -e "s/{n}/${n}/g" -e "s/{r}/${r}/g" -e "s/{g}/${g}/g" -e "s/{y}/${y}/g" -e "s/{b}/${b}/g" -e "s/{m}/${m}/g" -e "s/{c}/${c}/g" -e "s/{w}/${w}/g"'
HIGHS=' -e "s/{N}/${N}/g" -e "s/{R}/${R}/g" -e "s/{G}/${G}/g" -e "s/{Y}/${Y}/g" -e "s/{B}/${B}/g" -e "s/{M}/${M}/g" -e "s/{C}/${C}/g" -e "s/{W}/${W}/g"'
REVLOWS=' -e "s/{Rn}/${Rn}/g" -e "s/{Rr}/${Rr}/g" -e "s/{Rg}/${Rg}/g" -e "s/{Ry}/${Ry}/g" -e "s/{Rb}/${Rb}/g" -e "s/{Rm}/${Rm}/g" -e "s/{Rc}/${Rc}/g" -e "s/{Rw}/${Rw}/g"'
REVHIGHS=' -e "s/{RN}/${RN}/g" -e "s/{RR}/${RR}/g" -e "s/{RG}/${RG}/g" -e "s/{RY}/${RY}/g" -e "s/{RB}/${RB}/g" -e "s/{RM}/${RM}/g" -e "s/{RC}/${RC}/g" -e "s/{RW}/${RW}/g"'
# COLORIZE Usage:
# command |${COLORIZE} ${LOWS} ${HIGHS} ${REVLOWS} ${REVHIGHS}
set +a
}
2. egrepi
and the egrepi function, effective and elegant: color cycling between 8 or more colors (your needs) AND tested under 3 different unix OS, with comments :
# egrepi() egrep with 8 REVERSE cyclic colorations on regexps almost like egrep
# egrepi
# current script will work for KSH88, KSH93, bash 2+, zsh, under AIX / Linux / SunOS
egrepi ()
{
args=$*
# colorList=wBcgymrN # KSH93 or bash 3+, not for AIX
# set -A color # needed with older sh
color[0]=$Rw; color[1]=$RB; color[2]=$Rc; color[3]=$Rg; color[4]=$Ry; color[5]=$Rm; color[6]=$Rr; color[7]=$RN; # this is the only one AIX solution
i=0
unset argsToGrep argsSedColor argsPerlColor
for arg in ${args}
do
[ "${arg}" == "." ] && arg=\. # if you wanna grep "."
# color=R${colorList:((${RANDOM: -1:1})):1} # bash RANDOMized colors
# color=R${colorList:$i:1} && let i++ && ((i==8)) && i=0 # KSH93 or bash 3+, not for AIX
argsToGrep="${argsToGrep}${argsToGrep:+|}${arg}"
# argsSedColor="${argsSedColor} -e s#${arg}#$n${!color}&${w}#gI" # AIX KSH88 do not recognise this fucking variable double expansion
# argsSedColor="${argsSedColor} -e s#${arg}#$n${color[$i]}&${w}#gI" # AIX neither do include sed with Ignore case
argsPerlColor="${argsPerlColor}${argsPerlColor:+,}s#${arg}#$n${color[$i]}$&${END}#gi" # So: gotta use perl
let i+=1 && ((i==8)) && i=0 # AIX KSH88 do not recognise "let i++"
done
# egrep -i "${argsToGrep}" | sed ${argsSedColor} | egrep -v "grep|sed" # AIX sed incompatibility with Ignore case
# (($# > 0)) && (egrep -i "${argsToGrep}" | perl -p -e ${argsPerlColor}) || cat # this line colors & grep the words, will NOT act as "tail -f"
(($# > 0)) && (perl -p -e ${argsPerlColor}) || cat # this line just colors the words
}
3. Usage
command | egrepi word1 .. wordN
add a comment |
sure !
I wrote long a go a function called "egrepi", based on the 8 color variables definitions.
This works ONLY piped like a "tail -f" colored function.
1. setColors
first, the color variables function to be called at first:
setColors ()
{
set -a
which printf >/dev/null 2>&1 && print=printf || print=print # Mandriva doesn't know about printf
hide='eval tput civis'
show='eval tput cnorm'
CLS=$(tput clear)
bel=$(tput bel)
case ${UNAME} in
AIX)
# text / foreground
N=$(${print} '33[1;30m')
n=$(${print} '33[0;30m')
R=$(${print} '33[1;31m')
r=$(${print} '33[0;31m')
G=$(${print} '33[1;32m')
g=$(${print} '33[0;32m')
Y=$(${print} '33[1;33m')
y=$(${print} '33[0;33m')
B=$(${print} '33[1;34m')
b=$(${print} '33[0;34m')
M=$(${print} '33[1;35m')
m=$(${print} '33[0;35m')
C=$(${print} '33[1;36m')
c=$(${print} '33[0;36m')
W=$(${print} '33[1;37m')
w=$(${print} '33[0;37m')
END=$(${print} '33[0m')
# background
RN=$(${print} '33[6;40m')
Rn=$(${print} '33[40m')
RR=$(${print} '33[6;41m')
Rr=$(${print} '33[41m')
RG=$(${print} '33[6;42m')
Rg=$(${print} '33[42m')
RY=$(${print} '33[6;43m')
Ry=$(${print} '33[43m')
RB=$(${print} '33[6;44m')
Rb=$(${print} '33[44m')
RM=$(${print} '33[6;45m')
Rm=$(${print} '33[45m')
RC=$(${print} '33[6;46m')
Rc=$(${print} '33[46m')
RW=$(${print} '33[6;47m')
Rw=$(${print} '33[47m')
HIGH=$(tput bold)
SMUL=$(tput smul)
RMUL=$(tput rmul)
BLINK=$(tput blink)
REVERSE=$(tput smso)
REVERSO=$(tput rmso)
;;
*)
# text / foreground
n=$(tput setaf 0)
r=$(tput setaf 1)
g=$(tput setaf 2)
y=$(tput setaf 3)
b=$(tput setaf 4)
m=$(tput setaf 5)
c=$(tput setaf 6)
w=$(tput setaf 7)
N=$(tput setaf 8)
R=$(tput setaf 9)
G=$(tput setaf 10)
Y=$(tput setaf 11)
B=$(tput setaf 12)
M=$(tput setaf 13)
C=$(tput setaf 14)
W=$(tput setaf 15)
END=$(tput sgr0)
HIGH=$(tput bold)
SMUL=$(tput smul)
RMUL=$(tput rmul)
BLINK=$(tput blink)
REVERSE=$(tput smso)
REVERSO=$(tput rmso)
# background
Rn=$(tput setab 0)
Rr=$(tput setab 1)
Rg=$(tput setab 2)
Ry=$(tput setab 3)
Rb=$(tput setab 4)
Rm=$(tput setab 5)
Rc=$(tput setab 6)
Rw=$(tput setab 7)
RN=$(tput setab 8)
RR=$(tput setab 9)
RG=$(tput setab 10)
RY=$(tput setab 11)
RB=$(tput setab 12)
RM=$(tput setab 13)
RC=$(tput setab 14)
RW=$(tput setab 15)
;;
esac
BLUEf=${B}
BLUE=${b}
REDf=${R}
RED=${r}
GREENf=${G}
GREEN=${g}
YELLOWf=${Y}
YELLOW=${y}
MANGENTAf=${M}
MANGENTA=${m}
WHITEf=${W}
WHITE=${w}
CYANf=${C}
CYAN=${c}
OK="${RG}${n}OK${END}"
KO="${RR}${n}KO${END}"
NA="${N}NA${END}"
COLORIZE='eval sed -e "s/{END}/${END}/g" -e "s/{HIGH}/${HIGH}/g" -e "s/{SMUL}/${SMUL}/g" -e "s/{RMUL}/${RMUL}/g" -e "s/{BLINK}/${BLINK}/g" -e "s/{REVERSE}/${REVERSE}/g" -e "s/{REVERSO}/${REVERSO}/g"'
LOWS=' -e "s/{n}/${n}/g" -e "s/{r}/${r}/g" -e "s/{g}/${g}/g" -e "s/{y}/${y}/g" -e "s/{b}/${b}/g" -e "s/{m}/${m}/g" -e "s/{c}/${c}/g" -e "s/{w}/${w}/g"'
HIGHS=' -e "s/{N}/${N}/g" -e "s/{R}/${R}/g" -e "s/{G}/${G}/g" -e "s/{Y}/${Y}/g" -e "s/{B}/${B}/g" -e "s/{M}/${M}/g" -e "s/{C}/${C}/g" -e "s/{W}/${W}/g"'
REVLOWS=' -e "s/{Rn}/${Rn}/g" -e "s/{Rr}/${Rr}/g" -e "s/{Rg}/${Rg}/g" -e "s/{Ry}/${Ry}/g" -e "s/{Rb}/${Rb}/g" -e "s/{Rm}/${Rm}/g" -e "s/{Rc}/${Rc}/g" -e "s/{Rw}/${Rw}/g"'
REVHIGHS=' -e "s/{RN}/${RN}/g" -e "s/{RR}/${RR}/g" -e "s/{RG}/${RG}/g" -e "s/{RY}/${RY}/g" -e "s/{RB}/${RB}/g" -e "s/{RM}/${RM}/g" -e "s/{RC}/${RC}/g" -e "s/{RW}/${RW}/g"'
# COLORIZE Usage:
# command |${COLORIZE} ${LOWS} ${HIGHS} ${REVLOWS} ${REVHIGHS}
set +a
}
2. egrepi
and the egrepi function, effective and elegant: color cycling between 8 or more colors (your needs) AND tested under 3 different unix OS, with comments :
# egrepi() egrep with 8 REVERSE cyclic colorations on regexps almost like egrep
# egrepi
# current script will work for KSH88, KSH93, bash 2+, zsh, under AIX / Linux / SunOS
egrepi ()
{
args=$*
# colorList=wBcgymrN # KSH93 or bash 3+, not for AIX
# set -A color # needed with older sh
color[0]=$Rw; color[1]=$RB; color[2]=$Rc; color[3]=$Rg; color[4]=$Ry; color[5]=$Rm; color[6]=$Rr; color[7]=$RN; # this is the only one AIX solution
i=0
unset argsToGrep argsSedColor argsPerlColor
for arg in ${args}
do
[ "${arg}" == "." ] && arg=\. # if you wanna grep "."
# color=R${colorList:((${RANDOM: -1:1})):1} # bash RANDOMized colors
# color=R${colorList:$i:1} && let i++ && ((i==8)) && i=0 # KSH93 or bash 3+, not for AIX
argsToGrep="${argsToGrep}${argsToGrep:+|}${arg}"
# argsSedColor="${argsSedColor} -e s#${arg}#$n${!color}&${w}#gI" # AIX KSH88 do not recognise this fucking variable double expansion
# argsSedColor="${argsSedColor} -e s#${arg}#$n${color[$i]}&${w}#gI" # AIX neither do include sed with Ignore case
argsPerlColor="${argsPerlColor}${argsPerlColor:+,}s#${arg}#$n${color[$i]}$&${END}#gi" # So: gotta use perl
let i+=1 && ((i==8)) && i=0 # AIX KSH88 do not recognise "let i++"
done
# egrep -i "${argsToGrep}" | sed ${argsSedColor} | egrep -v "grep|sed" # AIX sed incompatibility with Ignore case
# (($# > 0)) && (egrep -i "${argsToGrep}" | perl -p -e ${argsPerlColor}) || cat # this line colors & grep the words, will NOT act as "tail -f"
(($# > 0)) && (perl -p -e ${argsPerlColor}) || cat # this line just colors the words
}
3. Usage
command | egrepi word1 .. wordN
add a comment |
sure !
I wrote long a go a function called "egrepi", based on the 8 color variables definitions.
This works ONLY piped like a "tail -f" colored function.
1. setColors
first, the color variables function to be called at first:
setColors ()
{
set -a
which printf >/dev/null 2>&1 && print=printf || print=print # Mandriva doesn't know about printf
hide='eval tput civis'
show='eval tput cnorm'
CLS=$(tput clear)
bel=$(tput bel)
case ${UNAME} in
AIX)
# text / foreground
N=$(${print} '33[1;30m')
n=$(${print} '33[0;30m')
R=$(${print} '33[1;31m')
r=$(${print} '33[0;31m')
G=$(${print} '33[1;32m')
g=$(${print} '33[0;32m')
Y=$(${print} '33[1;33m')
y=$(${print} '33[0;33m')
B=$(${print} '33[1;34m')
b=$(${print} '33[0;34m')
M=$(${print} '33[1;35m')
m=$(${print} '33[0;35m')
C=$(${print} '33[1;36m')
c=$(${print} '33[0;36m')
W=$(${print} '33[1;37m')
w=$(${print} '33[0;37m')
END=$(${print} '33[0m')
# background
RN=$(${print} '33[6;40m')
Rn=$(${print} '33[40m')
RR=$(${print} '33[6;41m')
Rr=$(${print} '33[41m')
RG=$(${print} '33[6;42m')
Rg=$(${print} '33[42m')
RY=$(${print} '33[6;43m')
Ry=$(${print} '33[43m')
RB=$(${print} '33[6;44m')
Rb=$(${print} '33[44m')
RM=$(${print} '33[6;45m')
Rm=$(${print} '33[45m')
RC=$(${print} '33[6;46m')
Rc=$(${print} '33[46m')
RW=$(${print} '33[6;47m')
Rw=$(${print} '33[47m')
HIGH=$(tput bold)
SMUL=$(tput smul)
RMUL=$(tput rmul)
BLINK=$(tput blink)
REVERSE=$(tput smso)
REVERSO=$(tput rmso)
;;
*)
# text / foreground
n=$(tput setaf 0)
r=$(tput setaf 1)
g=$(tput setaf 2)
y=$(tput setaf 3)
b=$(tput setaf 4)
m=$(tput setaf 5)
c=$(tput setaf 6)
w=$(tput setaf 7)
N=$(tput setaf 8)
R=$(tput setaf 9)
G=$(tput setaf 10)
Y=$(tput setaf 11)
B=$(tput setaf 12)
M=$(tput setaf 13)
C=$(tput setaf 14)
W=$(tput setaf 15)
END=$(tput sgr0)
HIGH=$(tput bold)
SMUL=$(tput smul)
RMUL=$(tput rmul)
BLINK=$(tput blink)
REVERSE=$(tput smso)
REVERSO=$(tput rmso)
# background
Rn=$(tput setab 0)
Rr=$(tput setab 1)
Rg=$(tput setab 2)
Ry=$(tput setab 3)
Rb=$(tput setab 4)
Rm=$(tput setab 5)
Rc=$(tput setab 6)
Rw=$(tput setab 7)
RN=$(tput setab 8)
RR=$(tput setab 9)
RG=$(tput setab 10)
RY=$(tput setab 11)
RB=$(tput setab 12)
RM=$(tput setab 13)
RC=$(tput setab 14)
RW=$(tput setab 15)
;;
esac
BLUEf=${B}
BLUE=${b}
REDf=${R}
RED=${r}
GREENf=${G}
GREEN=${g}
YELLOWf=${Y}
YELLOW=${y}
MANGENTAf=${M}
MANGENTA=${m}
WHITEf=${W}
WHITE=${w}
CYANf=${C}
CYAN=${c}
OK="${RG}${n}OK${END}"
KO="${RR}${n}KO${END}"
NA="${N}NA${END}"
COLORIZE='eval sed -e "s/{END}/${END}/g" -e "s/{HIGH}/${HIGH}/g" -e "s/{SMUL}/${SMUL}/g" -e "s/{RMUL}/${RMUL}/g" -e "s/{BLINK}/${BLINK}/g" -e "s/{REVERSE}/${REVERSE}/g" -e "s/{REVERSO}/${REVERSO}/g"'
LOWS=' -e "s/{n}/${n}/g" -e "s/{r}/${r}/g" -e "s/{g}/${g}/g" -e "s/{y}/${y}/g" -e "s/{b}/${b}/g" -e "s/{m}/${m}/g" -e "s/{c}/${c}/g" -e "s/{w}/${w}/g"'
HIGHS=' -e "s/{N}/${N}/g" -e "s/{R}/${R}/g" -e "s/{G}/${G}/g" -e "s/{Y}/${Y}/g" -e "s/{B}/${B}/g" -e "s/{M}/${M}/g" -e "s/{C}/${C}/g" -e "s/{W}/${W}/g"'
REVLOWS=' -e "s/{Rn}/${Rn}/g" -e "s/{Rr}/${Rr}/g" -e "s/{Rg}/${Rg}/g" -e "s/{Ry}/${Ry}/g" -e "s/{Rb}/${Rb}/g" -e "s/{Rm}/${Rm}/g" -e "s/{Rc}/${Rc}/g" -e "s/{Rw}/${Rw}/g"'
REVHIGHS=' -e "s/{RN}/${RN}/g" -e "s/{RR}/${RR}/g" -e "s/{RG}/${RG}/g" -e "s/{RY}/${RY}/g" -e "s/{RB}/${RB}/g" -e "s/{RM}/${RM}/g" -e "s/{RC}/${RC}/g" -e "s/{RW}/${RW}/g"'
# COLORIZE Usage:
# command |${COLORIZE} ${LOWS} ${HIGHS} ${REVLOWS} ${REVHIGHS}
set +a
}
2. egrepi
and the egrepi function, effective and elegant: color cycling between 8 or more colors (your needs) AND tested under 3 different unix OS, with comments :
# egrepi() egrep with 8 REVERSE cyclic colorations on regexps almost like egrep
# egrepi
# current script will work for KSH88, KSH93, bash 2+, zsh, under AIX / Linux / SunOS
egrepi ()
{
args=$*
# colorList=wBcgymrN # KSH93 or bash 3+, not for AIX
# set -A color # needed with older sh
color[0]=$Rw; color[1]=$RB; color[2]=$Rc; color[3]=$Rg; color[4]=$Ry; color[5]=$Rm; color[6]=$Rr; color[7]=$RN; # this is the only one AIX solution
i=0
unset argsToGrep argsSedColor argsPerlColor
for arg in ${args}
do
[ "${arg}" == "." ] && arg=\. # if you wanna grep "."
# color=R${colorList:((${RANDOM: -1:1})):1} # bash RANDOMized colors
# color=R${colorList:$i:1} && let i++ && ((i==8)) && i=0 # KSH93 or bash 3+, not for AIX
argsToGrep="${argsToGrep}${argsToGrep:+|}${arg}"
# argsSedColor="${argsSedColor} -e s#${arg}#$n${!color}&${w}#gI" # AIX KSH88 do not recognise this fucking variable double expansion
# argsSedColor="${argsSedColor} -e s#${arg}#$n${color[$i]}&${w}#gI" # AIX neither do include sed with Ignore case
argsPerlColor="${argsPerlColor}${argsPerlColor:+,}s#${arg}#$n${color[$i]}$&${END}#gi" # So: gotta use perl
let i+=1 && ((i==8)) && i=0 # AIX KSH88 do not recognise "let i++"
done
# egrep -i "${argsToGrep}" | sed ${argsSedColor} | egrep -v "grep|sed" # AIX sed incompatibility with Ignore case
# (($# > 0)) && (egrep -i "${argsToGrep}" | perl -p -e ${argsPerlColor}) || cat # this line colors & grep the words, will NOT act as "tail -f"
(($# > 0)) && (perl -p -e ${argsPerlColor}) || cat # this line just colors the words
}
3. Usage
command | egrepi word1 .. wordN
sure !
I wrote long a go a function called "egrepi", based on the 8 color variables definitions.
This works ONLY piped like a "tail -f" colored function.
1. setColors
first, the color variables function to be called at first:
setColors ()
{
set -a
which printf >/dev/null 2>&1 && print=printf || print=print # Mandriva doesn't know about printf
hide='eval tput civis'
show='eval tput cnorm'
CLS=$(tput clear)
bel=$(tput bel)
case ${UNAME} in
AIX)
# text / foreground
N=$(${print} '33[1;30m')
n=$(${print} '33[0;30m')
R=$(${print} '33[1;31m')
r=$(${print} '33[0;31m')
G=$(${print} '33[1;32m')
g=$(${print} '33[0;32m')
Y=$(${print} '33[1;33m')
y=$(${print} '33[0;33m')
B=$(${print} '33[1;34m')
b=$(${print} '33[0;34m')
M=$(${print} '33[1;35m')
m=$(${print} '33[0;35m')
C=$(${print} '33[1;36m')
c=$(${print} '33[0;36m')
W=$(${print} '33[1;37m')
w=$(${print} '33[0;37m')
END=$(${print} '33[0m')
# background
RN=$(${print} '33[6;40m')
Rn=$(${print} '33[40m')
RR=$(${print} '33[6;41m')
Rr=$(${print} '33[41m')
RG=$(${print} '33[6;42m')
Rg=$(${print} '33[42m')
RY=$(${print} '33[6;43m')
Ry=$(${print} '33[43m')
RB=$(${print} '33[6;44m')
Rb=$(${print} '33[44m')
RM=$(${print} '33[6;45m')
Rm=$(${print} '33[45m')
RC=$(${print} '33[6;46m')
Rc=$(${print} '33[46m')
RW=$(${print} '33[6;47m')
Rw=$(${print} '33[47m')
HIGH=$(tput bold)
SMUL=$(tput smul)
RMUL=$(tput rmul)
BLINK=$(tput blink)
REVERSE=$(tput smso)
REVERSO=$(tput rmso)
;;
*)
# text / foreground
n=$(tput setaf 0)
r=$(tput setaf 1)
g=$(tput setaf 2)
y=$(tput setaf 3)
b=$(tput setaf 4)
m=$(tput setaf 5)
c=$(tput setaf 6)
w=$(tput setaf 7)
N=$(tput setaf 8)
R=$(tput setaf 9)
G=$(tput setaf 10)
Y=$(tput setaf 11)
B=$(tput setaf 12)
M=$(tput setaf 13)
C=$(tput setaf 14)
W=$(tput setaf 15)
END=$(tput sgr0)
HIGH=$(tput bold)
SMUL=$(tput smul)
RMUL=$(tput rmul)
BLINK=$(tput blink)
REVERSE=$(tput smso)
REVERSO=$(tput rmso)
# background
Rn=$(tput setab 0)
Rr=$(tput setab 1)
Rg=$(tput setab 2)
Ry=$(tput setab 3)
Rb=$(tput setab 4)
Rm=$(tput setab 5)
Rc=$(tput setab 6)
Rw=$(tput setab 7)
RN=$(tput setab 8)
RR=$(tput setab 9)
RG=$(tput setab 10)
RY=$(tput setab 11)
RB=$(tput setab 12)
RM=$(tput setab 13)
RC=$(tput setab 14)
RW=$(tput setab 15)
;;
esac
BLUEf=${B}
BLUE=${b}
REDf=${R}
RED=${r}
GREENf=${G}
GREEN=${g}
YELLOWf=${Y}
YELLOW=${y}
MANGENTAf=${M}
MANGENTA=${m}
WHITEf=${W}
WHITE=${w}
CYANf=${C}
CYAN=${c}
OK="${RG}${n}OK${END}"
KO="${RR}${n}KO${END}"
NA="${N}NA${END}"
COLORIZE='eval sed -e "s/{END}/${END}/g" -e "s/{HIGH}/${HIGH}/g" -e "s/{SMUL}/${SMUL}/g" -e "s/{RMUL}/${RMUL}/g" -e "s/{BLINK}/${BLINK}/g" -e "s/{REVERSE}/${REVERSE}/g" -e "s/{REVERSO}/${REVERSO}/g"'
LOWS=' -e "s/{n}/${n}/g" -e "s/{r}/${r}/g" -e "s/{g}/${g}/g" -e "s/{y}/${y}/g" -e "s/{b}/${b}/g" -e "s/{m}/${m}/g" -e "s/{c}/${c}/g" -e "s/{w}/${w}/g"'
HIGHS=' -e "s/{N}/${N}/g" -e "s/{R}/${R}/g" -e "s/{G}/${G}/g" -e "s/{Y}/${Y}/g" -e "s/{B}/${B}/g" -e "s/{M}/${M}/g" -e "s/{C}/${C}/g" -e "s/{W}/${W}/g"'
REVLOWS=' -e "s/{Rn}/${Rn}/g" -e "s/{Rr}/${Rr}/g" -e "s/{Rg}/${Rg}/g" -e "s/{Ry}/${Ry}/g" -e "s/{Rb}/${Rb}/g" -e "s/{Rm}/${Rm}/g" -e "s/{Rc}/${Rc}/g" -e "s/{Rw}/${Rw}/g"'
REVHIGHS=' -e "s/{RN}/${RN}/g" -e "s/{RR}/${RR}/g" -e "s/{RG}/${RG}/g" -e "s/{RY}/${RY}/g" -e "s/{RB}/${RB}/g" -e "s/{RM}/${RM}/g" -e "s/{RC}/${RC}/g" -e "s/{RW}/${RW}/g"'
# COLORIZE Usage:
# command |${COLORIZE} ${LOWS} ${HIGHS} ${REVLOWS} ${REVHIGHS}
set +a
}
2. egrepi
and the egrepi function, effective and elegant: color cycling between 8 or more colors (your needs) AND tested under 3 different unix OS, with comments :
# egrepi() egrep with 8 REVERSE cyclic colorations on regexps almost like egrep
# egrepi
# current script will work for KSH88, KSH93, bash 2+, zsh, under AIX / Linux / SunOS
egrepi ()
{
args=$*
# colorList=wBcgymrN # KSH93 or bash 3+, not for AIX
# set -A color # needed with older sh
color[0]=$Rw; color[1]=$RB; color[2]=$Rc; color[3]=$Rg; color[4]=$Ry; color[5]=$Rm; color[6]=$Rr; color[7]=$RN; # this is the only one AIX solution
i=0
unset argsToGrep argsSedColor argsPerlColor
for arg in ${args}
do
[ "${arg}" == "." ] && arg=\. # if you wanna grep "."
# color=R${colorList:((${RANDOM: -1:1})):1} # bash RANDOMized colors
# color=R${colorList:$i:1} && let i++ && ((i==8)) && i=0 # KSH93 or bash 3+, not for AIX
argsToGrep="${argsToGrep}${argsToGrep:+|}${arg}"
# argsSedColor="${argsSedColor} -e s#${arg}#$n${!color}&${w}#gI" # AIX KSH88 do not recognise this fucking variable double expansion
# argsSedColor="${argsSedColor} -e s#${arg}#$n${color[$i]}&${w}#gI" # AIX neither do include sed with Ignore case
argsPerlColor="${argsPerlColor}${argsPerlColor:+,}s#${arg}#$n${color[$i]}$&${END}#gi" # So: gotta use perl
let i+=1 && ((i==8)) && i=0 # AIX KSH88 do not recognise "let i++"
done
# egrep -i "${argsToGrep}" | sed ${argsSedColor} | egrep -v "grep|sed" # AIX sed incompatibility with Ignore case
# (($# > 0)) && (egrep -i "${argsToGrep}" | perl -p -e ${argsPerlColor}) || cat # this line colors & grep the words, will NOT act as "tail -f"
(($# > 0)) && (perl -p -e ${argsPerlColor}) || cat # this line just colors the words
}
3. Usage
command | egrepi word1 .. wordN
edited Apr 6 '13 at 22:37
answered Apr 6 '13 at 22:02
scavengerscavenger
6113
6113
add a comment |
add a comment |
You might also want to take a look at lwatch:
tail -f /var/log/syslog | lwatch --input -
add a comment |
You might also want to take a look at lwatch:
tail -f /var/log/syslog | lwatch --input -
add a comment |
You might also want to take a look at lwatch:
tail -f /var/log/syslog | lwatch --input -
You might also want to take a look at lwatch:
tail -f /var/log/syslog | lwatch --input -
answered Jun 17 '15 at 20:52
Michael KruppMichael Krupp
1113
1113
add a comment |
add a comment |
grc for sure!
customize your collors with regex in the file: ~.grc/conf.tail (or whatever name you want)
regexp=.*(select .*)$
colours=unchanged,cyan
=====
regexp=.*(update .*)$
colours=unchanged,bold yellow
=====
regexp=.*(insert .*)$
colours=unchanged,bold yellow
=====
regexp=.*(emp=d+).*
colours=unchanged,reverse green
=====
regexp=.*http.*/rest/contahub.cmds.(.*?)/(w*).*$
colours=unchanged,green,magenta
=====
regexp=.*http.*/M/.*.(.*?Facade)/(w*).*$
colours=unchanged,underline green,underline magenta
command line:
grc -c conf.tail tail -f log/tomcat/catalina.out
results:
info for configuring grc:
https://github.com/manjuraj/config/blob/master/.grc/sample.conf
add a comment |
grc for sure!
customize your collors with regex in the file: ~.grc/conf.tail (or whatever name you want)
regexp=.*(select .*)$
colours=unchanged,cyan
=====
regexp=.*(update .*)$
colours=unchanged,bold yellow
=====
regexp=.*(insert .*)$
colours=unchanged,bold yellow
=====
regexp=.*(emp=d+).*
colours=unchanged,reverse green
=====
regexp=.*http.*/rest/contahub.cmds.(.*?)/(w*).*$
colours=unchanged,green,magenta
=====
regexp=.*http.*/M/.*.(.*?Facade)/(w*).*$
colours=unchanged,underline green,underline magenta
command line:
grc -c conf.tail tail -f log/tomcat/catalina.out
results:
info for configuring grc:
https://github.com/manjuraj/config/blob/master/.grc/sample.conf
add a comment |
grc for sure!
customize your collors with regex in the file: ~.grc/conf.tail (or whatever name you want)
regexp=.*(select .*)$
colours=unchanged,cyan
=====
regexp=.*(update .*)$
colours=unchanged,bold yellow
=====
regexp=.*(insert .*)$
colours=unchanged,bold yellow
=====
regexp=.*(emp=d+).*
colours=unchanged,reverse green
=====
regexp=.*http.*/rest/contahub.cmds.(.*?)/(w*).*$
colours=unchanged,green,magenta
=====
regexp=.*http.*/M/.*.(.*?Facade)/(w*).*$
colours=unchanged,underline green,underline magenta
command line:
grc -c conf.tail tail -f log/tomcat/catalina.out
results:
info for configuring grc:
https://github.com/manjuraj/config/blob/master/.grc/sample.conf
grc for sure!
customize your collors with regex in the file: ~.grc/conf.tail (or whatever name you want)
regexp=.*(select .*)$
colours=unchanged,cyan
=====
regexp=.*(update .*)$
colours=unchanged,bold yellow
=====
regexp=.*(insert .*)$
colours=unchanged,bold yellow
=====
regexp=.*(emp=d+).*
colours=unchanged,reverse green
=====
regexp=.*http.*/rest/contahub.cmds.(.*?)/(w*).*$
colours=unchanged,green,magenta
=====
regexp=.*http.*/M/.*.(.*?Facade)/(w*).*$
colours=unchanged,underline green,underline magenta
command line:
grc -c conf.tail tail -f log/tomcat/catalina.out
results:
info for configuring grc:
https://github.com/manjuraj/config/blob/master/.grc/sample.conf
answered Nov 1 '16 at 22:27
FlavioFlavio
111
111
add a comment |
add a comment |
As for the color codes, I would use tput:
red=$( tput -Txterm setaf 1 )
norm=$( tput -Txterm sgr0 )
bold=$( tput -Txterm bold )
See for reference: man tput
Then:
tail -F myfile.log | sed "s/(.ERROR.*)/$red$bold1$norm/g"
Great, thanks. Works like a charm with standard shell functions.
– vquintans
Jul 13 '18 at 8:56
add a comment |
As for the color codes, I would use tput:
red=$( tput -Txterm setaf 1 )
norm=$( tput -Txterm sgr0 )
bold=$( tput -Txterm bold )
See for reference: man tput
Then:
tail -F myfile.log | sed "s/(.ERROR.*)/$red$bold1$norm/g"
Great, thanks. Works like a charm with standard shell functions.
– vquintans
Jul 13 '18 at 8:56
add a comment |
As for the color codes, I would use tput:
red=$( tput -Txterm setaf 1 )
norm=$( tput -Txterm sgr0 )
bold=$( tput -Txterm bold )
See for reference: man tput
Then:
tail -F myfile.log | sed "s/(.ERROR.*)/$red$bold1$norm/g"
As for the color codes, I would use tput:
red=$( tput -Txterm setaf 1 )
norm=$( tput -Txterm sgr0 )
bold=$( tput -Txterm bold )
See for reference: man tput
Then:
tail -F myfile.log | sed "s/(.ERROR.*)/$red$bold1$norm/g"
edited Jul 13 '18 at 10:05
vquintans
1034
1034
answered Jun 2 '16 at 9:12
Fabien BouleauFabien Bouleau
1192
1192
Great, thanks. Works like a charm with standard shell functions.
– vquintans
Jul 13 '18 at 8:56
add a comment |
Great, thanks. Works like a charm with standard shell functions.
– vquintans
Jul 13 '18 at 8:56
Great, thanks. Works like a charm with standard shell functions.
– vquintans
Jul 13 '18 at 8:56
Great, thanks. Works like a charm with standard shell functions.
– vquintans
Jul 13 '18 at 8:56
add a comment |
Publishes some time ago Node Js utility - log-color-highlight
tail -f file | lch -red error warn -green success
lch -f file -red.bold error warn -underline.bgGreen success
add a comment |
Publishes some time ago Node Js utility - log-color-highlight
tail -f file | lch -red error warn -green success
lch -f file -red.bold error warn -underline.bgGreen success
add a comment |
Publishes some time ago Node Js utility - log-color-highlight
tail -f file | lch -red error warn -green success
lch -f file -red.bold error warn -underline.bgGreen success
Publishes some time ago Node Js utility - log-color-highlight
tail -f file | lch -red error warn -green success
lch -f file -red.bold error warn -underline.bgGreen success
edited Jan 6 '17 at 20:38
phord
1074
1074
answered Aug 19 '15 at 10:27
gliviugliviu
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f8414%2fhow-to-have-tail-f-show-colored-output%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
one-line
sed
: stackoverflow.com/a/14691971/52074– Trevor Boyd Smith
Sep 14 '18 at 18:45