Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

1 Answer 1

up vote 1 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 at 14:13

Your Answer

 
discard

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.