How do we use sed to filter lines by two criteria?
aptitude -v show '?name(grep)' | egrep --color=always "^|grep" | sed 's/^\(Package: .*\)$/\x1b[33;1m\1\x1b[0m/'
In the above, what I'm trying to do is first use grep to color any found matches of my search string ('grep' in this example), and then color all 'Package: ...' heading lines in aptitude's output yellow. However if any 'Package: ...' line has previously had red color added to it by the egrep ... command, what happens is that the line starts yellow, converts to red for the found 'grep' string, and then reverts to normal color when '\e[0m' is found (as I'd expect).
So, it seems to me that what I have to do is find any 'Package: ...' lines and then, in only those lines, strip out possible color codes before coloring the whole line yellow.
... will strip out the codes, but I need to only run that on the lines starting with 'Package: ....'. What's the spell? Or, might there be a more elegant way to do this?