Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I like the way vim highlights the output from syslog. However, I only want the most recent outputs to be opened. I tried

grep --color=always "$@" /var/log/syslog  > /tmp/fileOUT
vim /tmp/fileOUT

but it gives the bash color output like [033;m blah blah. If I don't include --color=always, there is no color at all. How can I do this? (I'm using bash)

share|improve this question
up vote 2 down vote accepted

Well, vim uses color template files for syntax highlighting. This has nothing to do with the output of grep which uses ANSI escape sequences (the \[033; stuff you mentioned).

My vim doesn't have a style file for syslog and does not color it (I checked both on Debian and on Ubuntu 14.04). If you look at the relevant file on your system, you will find it starts with a regular expression that defines the files to match against. So, if you make your /tmp/fileOUT match that syntax, it should be colored. Don't use --color=always, that will just screw things up.

Alternatively, you could use source-highlight. Install it with sudo apt-get install source-highlight and then run:

sudo tail -n 50 /var/log/syslog | source-highlight --out-format=esc -o STDOUT -s log

The command above will color the last 50 lines of /var/log/syslog:

enter image description here

share|improve this answer
Heck yeah! Even better than having to type in the most recent time as a string (the "$@"), as my script was doing. Thanks. – MrUser May 9 '14 at 14:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.