Reputation: 1364
I'm searching for a regex code which lists all the lines that contain an a OR an i. I tryed this:
grep -E '[(a|i)]{1}' testFile.txt
but this gives me the words containing a or i and words that contain a en i. What's wrong?
Upvotes: 14
Views: 38594
Reputation: 37365
You can achieve that with:
grep -E "^[^ai]*(a|i){1}[^ai]*$" testFile.txt
Upvotes: 9
Reputation: 3464
If you want an exclusive OR then try this:
grep -E '^[^i]*a[^i]*$|^[^a]*i[^a]*$'
Upvotes: 0