0

Hi I have lots of logfiles with ^[[1m (as vim displays it) in them. I want to watch a logfile life via

tail -n 1000 -f logfile.log | grep <expression-for-escape-sequence>

and only get lines that have bold in them. I am not sure which grep options I should use and have tried the following already:

tail -n 1000 -f logfile.log | grep "\033\0133\061\0155"
tail -n 1000 -f logfile.log | grep "\033\01331m"
tail -n 1000 -f logfile.log | grep "\033\[1m"

It does not work though... And yes there are bold lines in the last 1000 lines of logfile.log, testing with

echo -e "\033\01331mTest\033\01330m" | grep ...

same results... ;)

Appreciate any help!

Anon
  • 1
  • 2

2 Answers2

2

Use single quotes with a dollar sign in front—as in $'...'—to have the shell convert the \033 escape sequence into an ESC character:

tail -n 1000 -f logfile.log | grep $'\033\[1m'

From man bash:

Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • Thanks! this is exactly what I was looking for! It was really a nightmare searching google for a solution because of all the special characters ;) ! – Anon Sep 02 '10 at 21:53
0

This works (in a POSIX shell, not necessarily bash):

echo -e "\033\01331mTest\033\01330m" | grep "$(printf "\x1b\\[1m")"
jpalecek
  • 47,058
  • 7
  • 102
  • 144