If you are greping through monochrome logs, you're missing out on color.
Here's my latest:
grep -l search criteria * | xargs head | awk -f colorit.awk | moregreat for spam logs.
Your presence here is welcome.
grep -l search criteria * | xargs head | awk -f colorit.awk | moreless can be useful. ETA: Oh, yeah, the point was to add "before" context to tail-f filename | grep "search" , similar to how grep does it on static files. In this case, it's more of tail -f filename | awk -f thisfile.awk, and you could also pipe that through my awk colorizer for the double whammy: context (before and after search) plus color.
BEGIN {
numlinesbefore = 3
numlinesafter = 3
needle = "search"
aftercount = -1
head = ""
tail = ""
}
{
before[numlinesbefore] = $0
for (i = 0; i < numlinesbefore; i++) {
before[i] = before[i+1]
}
if ($0 ~ needle) {
for (i = 0; i < numlinesbefore-1; i++) {
head = head "\n" before[i]
}
aftercount = numlinesafter + 1
tail = ""
print head
}
if (aftercount >= 0) {
print $0
--aftercount
}
if (aftercount == 0 ) {
head = ""
tail = ""
print "---"
aftercount = -1
}
}
tail -f maillog.txt | grep "search" is that I really did want to watch the noise and not just the signal. Except that I'd like to notice the signal. Here's my printcolor.awk Now I can use tail -f maillog.txt | awk -f printcolor.awk and see the whole tail, with keywords highlighted in *different* colors.
function colorize(word, color)
{
c["red"] = "^[[1;31;40m"
c["green"] = "^[[1;32;40m"
c["yellow"] = "^[[1;33;40m"
c["blue"] = "^[[1;34;40m"
c["magenta"] = "^[[1;35;40m"
if (line ~ word)
{ split (line, a, word)
line=a[1] c[color] (word) "^[[0;37;40m" a[2]
}
}
{line = $0
colorize("whitelist","green")
colorize("Bayesian Spam","red")
print line
}
"^G^[[1;32;40m" (not caret G)