I have two commands in
perl and one test file
$ cat test.txt aaa bla bbb foo #ccc bar ddd 444
perl expression colorizes any occurrence of
bbb with red color:
cat test.txt | perl -pe "s/(aaa|bbb)/\e[1;31m\1\033[0m/g"
Second expression colorizes green any line starting with
cat test.txt | perl -pe "s/^(#.*)/\e[0;32m\1\033[0m/g"
Now I need to combine these two expressions into one, having following properties:
if line starts with
#, then colorize whole line using green color.
If line does not start with
# colorize any occurrence of
bbb using red color.
In other words, if line is already green (i.e. typical; comment line), I don't want to color any possible occurrence of
bbb. Otherwise, I want to colorize them red.
How could I combine my two expressions to achieve this ?