Issue
I am using grep to find match of 2 patterns with condition OR like this, classically:
grep -E 'C_matrix|F_matrix' triplot_XC_dev_for_right_order_with_FoM.py | wc -l
I would like now to exclude the cases when both pattern are matched on the same line, i.e I would like to use a XOR operator with grep.
How can I do this operation ? Maybe another trick is possible (I think about grep -v
to exclude but this would be nice to do this operation in ony one command line with grep -E
).
Solution
When you want to make such a special case, it is better to make use of awk
:
$ awk '(/C_matrix/ && !/F_matrix/) || (!/C_matrix/ && !/F_matrix/)' file
Using GNU awk, you can use the bit-manipulation function xor
:
$ awk 'xor(/C_matrix/,/F_matrix/)' file
Answered By - kvantour