Page 1 of 1
a beginners Q about the grep command & colours
Posted: Tue Dec 31, 2024 7:05 am
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 (59.11 KiB) Viewed 231 times
Thanks!
Собака
Re: a beginners Q about the grep command & colours
Posted: Tue Dec 31, 2024 10:22 am
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.
Re: a beginners Q about the grep command & colours (good answer)
Posted: Wed Jan 01, 2025 7:48 am
by cobaka
Hello @Rantanplan
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
Re: a beginners Q about the grep command & colours
Posted: Wed Jan 01, 2025 4:33 pm
by Trapster
You can change the highlight color of grep by using an environment variable, GREP_COLOR, which you can set like this:
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