I have a simple bash
script. One line of my script matches a "pattern" with grep and colors the match
grep -i --color=always -- "$1"
I need to modify it, so that it only colors the match, if the line is not a comment (i.e. if it does not start with a #
). In other words: I still want grep to match the commented line, but without coloring it.
Let's say I have following text file (with added line numbers)
1 aaa PATTERN
2 bbb ccc PATTERN ddd
3 # eee PATTERN
4 fff ggg
I need my grep expression to match lines 1,2,3 but only color the lines which are not commented (1 and 2)