I want to search for the occurrence of multiple strings in each line and print the lines which have the two strings occurred. Find occurrence of a single string is trivial using grep. However, if I want to test the ocurrence of AB+CD
and nonCD
at the SAME LINE without considering their order (because using AB+CD.*nonCD
will always assume the AB+CD occurrence before nonCD
which is unsuitable for my case. This is a sample of the file content:
google.com,9,AB+CD,nonAB+nonCD
youtube.com,9,AB+CD,AB+CD
facebook.com,20,nonCD
If I try: grep -E 'AB+CD|nonCD' file1.txt
it prints:
google.com,9,AB+CD,nonAB+nonCD
facebook.com,20,nonCD
What I want is the occurrence of AB+CD
AND nonCD
in the same line togather without considering their order nor how many times they occurred.