I have three strings that I search for within a file. To find the lines with either one of them, I use
grep 'string1\|string2\|string3' file
I want to print out only the matched strings within each line, using the -o
flag. But in this case if two of the strings are present in the line, only one of them shows up. Is there a way to get something like string1
and/or string2
etc. without having to list 6 cases with and and or using this answer.
Note that I am using OS X Yosemite.
Expected output:
string1
string1 string2
string3
string1 string3
string3
etc.