On Thursday 05 April 2007 20:07, Tony Stohne wrote:
> Mick said the following on 2007-04-05 19:07:
> | ...
> | Hmm, neither less not cat give me color output.  Passing --color=y to
>
> either
>
> | tells me things like:
> | ==============================
> | There is no color=y option ("less --help" for help)
> | ==============================
> |
> | I also tried --color but it's all still shown in black & white.  How
>
> do you
>
> | pipe a file and get it to show in color?  Am I missing something in
> | my .bashrc or elsewhere?
>
> To make less interpret color escape sequences, you need the -R option.
> export LESS=-R in your shell startup script and you-ll have it as
> default. Generally, you don't want to use less -r, which allows
> arbitrary control characters through to affect the terminal (which tend
> to create major garbage).
>
> Color is added via ANSI escape sequences, which don't work in all
> displays/terminals/consoles, but as an example: grep is smart enough to
> detect this and won't use color (even when specified) if you're sending
> the output via a pipeline. Otherwise, if you piped the output, eg to
> less, the ANSI escape sequences would send garbage to the screen.
>
> ~ If, on the other hand, that's really what you want to do (without the
> garbage), there's a workaround:
>
> use the --color=always to force it through and call less with the -R
> flag (which prints ALL RAW control characters). That way, the color
> codes will escape correctly and you'll page through screens of text with
> your matched patterns in full color:
>
> grep --color=always "regexp" the_file_you_want_to_wade_through | less -R
>
> That should do the trick :)

Thank you Tony,

That's good.  It shows the regexp in colour and makes it easy to find amidst 
the text.  However, what I had in mind was many different colours, like I can 
see e.g. in vim?  Is such a thing possible with cat or less?

BTW, I had alias less="less -r" in my .bashrc, but changed to -R as suggested.

Happy Easter to All!
-- 
Regards,
Mick

Attachment: pgpgyxGMzC2RU.pgp
Description: PGP signature

Reply via email to