I want to extract the lines that matches the following logical operation:
"AB+CD" AND ("nonAB+nonCD" OR "nonAB+CD").
Which means I want lines with:
AB+CD,nonAB+nonCD AB+CD,nonAB+CD AB+CD,nonAB+nonCD,nonAB+CD
Meaning that I am looking for lines with "AB+CD" with one or both of ("nonAB+nonCD" OR "nonAB+CD").
Note that the + is part of the string. I want to treat it as a string (character) not arithmetic operation.
What I did is using pipe to execute AND. And use \| for the OR. So My command is:
grep ',AB+CD' test.txt | grep ',nonAB+nonCD\|,nonAB+CD'
| is for piping. The second is logical OR for grep as per this reference that gives this example for logical OR with grep:
grep 'pattern1\|pattern2' filename
The result that appears to me in the terminal colors (finds) the second part of the command. The first part (before the pipe
| is not highlighted in the colored result. My question:
1) Is my command correct?
2) How to color the complete command findings?