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)


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

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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