a beginners Q about the grep command & colours

New to Puppy and have questions? Start here

Moderator: Forum moderators

Post Reply
User avatar
cobaka
Posts: 584
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 99 times
Been thanked: 67 times

a beginners Q about the grep command & colours

Post by cobaka »

Hello all:

I use the program (or command) "grep" every day.
I would like to change the color used to display items shown by 'the switches".
You can see that the file name and paragraph number are presented in mauve and dark green.
It's difficult to read.
I would like to change these colors to something lighter - perhaps yellow or blue.

Where can I do that? That's my question.

Here is what I see:

terminal+grep_showing_colors.jpg
terminal+grep_showing_colors.jpg (59.11 KiB) Viewed 233 times

Thanks!

Собака

собака --> это Русский --> a dog
"c" -- say "s" - as in "see" or "scent" or "sob".

Rantanplan
Posts: 136
Joined: Thu Jun 03, 2021 2:25 pm
Has thanked: 53 times
Been thanked: 30 times

Re: a beginners Q about the grep command & colours

Post by Rantanplan »

Hello @cobaka ,

perhaps, "your" answer is here : https://askubuntu.com/questions/1042234 ... or-of-grep

I didn't test it.

I hope this will help you.

Best to you.

User avatar
cobaka
Posts: 584
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 99 times
Been thanked: 67 times

Re: a beginners Q about the grep command & colours (good answer)

Post by cobaka »

Hello @Rantanplan

perhaps, "your" answer is here : https://askubuntu.com/questions/1042234 ... or-of-grep

This link is quite helpful (and leads down a large 'rabbit hole').
It explains that the default display colors for grep are inherited from the terminal, but it's possible (I believe) to over-ride the terminal settings.
To invoke such changes, it's necessary to understand how to declare/set bash variables.

Thank you.

Leslie

собака --> это Русский --> a dog
"c" -- say "s" - as in "see" or "scent" or "sob".

User avatar
Trapster
Posts: 201
Joined: Sat Aug 01, 2020 7:44 pm
Location: Texas
Has thanked: 1 time
Been thanked: 61 times

Re: a beginners Q about the grep command & colours

Post by Trapster »

You can change the highlight color of grep by using an environment variable, GREP_COLOR, which you can set like this:

Code: Select all

export GREP_COLOR="01;32"

where "01" means: bold and "32" green. The default is "01:31" (bold red). Other colors:

31:red
32:green
33:yellow
34:blue
35:purple

then using

Code: Select all

grep --color searchword searchfile.txt

More info here:
https://askubuntu.com/questions/1042234 ... or-of-grep

Post Reply

Return to “Beginners Help”