Please can someone help me with a query. Will the following query bring back 'Jolly Brewers'. My understanding is that it will bring back either 'Jolly' or 'Brewers' but not 'Jolly Brewers'....because of the pipe
Maybe this excerpt from the egrep man page will help you to better understand how egrep works, note the sentence that I have underlined:
DESCRIPTION
grep searches the named input FILEs (or standard input if no files are
named, or the file name - is given) for lines containing a match to the
given PATTERN. By default, grep prints the matching lines.
---------- Post updated at 00:54 ---------- Previous update was at 00:50 ----------
$ egrep '(Jolly)|(Brewers)' public
Jolly Brewers
$ egrep -o '(Jolly)|(Brewers)' public
Jolly
Brewers
$
In fact in this case the pipe means AND as well as OR.
AFAIK it has nothing to do with the brackets, if you omit the brackets, the result should be the same.
Additionally note the difference between one pipe and two pipes, where the latter means OR in shell.
---------- Post updated at 01:32 ---------- Previous update was at 01:22 ----------
All right, I have to correct myself, one pipe does indeed mean OR Regular Expression Tutorial (Section "Alternation")
okay, I'm back to square one. The official answer to the question says that the following statement will return 'Jolly Brewers'....but how can it when pipe represents OR?
egrep '(Jolly)|(Brewers)' Public_Houses
The actual Solaris SCSAS question is fractionally different but I don't see how it would make any difference to the answer
Strange, after some more research, it looks like I initially was right with AND/OR... Finally I'll stick by my initial definition.
A pipe in the egrep pattern stands for a delimiter. A double pipe stands for OR.
However egrep will in both cases print the matching line (which contains both patterns).
Let me illustrate this:
$ egrep --color=always '(Jolly)|(Brewers)' public
Jolly Brewers
$ egrep --color=always '(Jolly)||(Brewers)' public
Jolly Brewers
$
--colour[=WHEN], --color[=WHEN]
Surround the matching string with the marker find in GREP_COLOR
environment variable. WHEN may be \`never', \`always', or \`auto'