Inverting match with grep, unless another term exists
I have a list containing a set of tags, and would like to exclude one tag, unless another tag exists in the line.
Say I have the following list, and want to exclude B
, unless A
is present.
<span style="color:#323232;">[A,B]
</span><span style="color:#323232;">[A,C]
</span><span style="color:#323232;">[B,C]
</span><span style="color:#323232;">[A]
</span><span style="color:#323232;">[B]
</span>
I can reverse grep for B
:
<span style="color:#323232;">> grep --invert-match "B"
</span><span style="color:#323232;">[A,C]
</span><span style="color:#323232;">[A]
</span>
How can I find the previous list, but also the item containing [A,B]
?