[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Regex Question



Telly Williams wrote:


	I'm reading up on Regular Expressions and I have a question about alternation.

	I have the sentences: "There was a dog in the house." & "A house on the hill."

	Both of these are in a file (named "regex") on two different lines.

	My understanding of alternation is that it will look both for what is on the right and left of the pipe.

So, if I type:
		grep in|hill regex

	isn't that supposed to give me both sentences in stdout?

	When I type that, I get nothing at all on return.  I've even typed it as:

		grep in\|hill regex

	and I still get nothing.  What am I doing wrong?  Is what I'm typing and what I'm asking for two different things?  Thanks.

Your issue is shell escaping.  Consider:

$ grep in\\\|hill input
There was a dog in the house.
A house on the hill.
$ grep 'in\|hill' input
There was a dog in the house.
A house on the hill.

In both of these, the argument that grep gets is 'in\|hill'.
In the first example you give, grep gets one argument, and
the output of grep is piped to hill, which probably doesn't
exist in your path.  In the second, grep gets the
argument "in|hill", and tries to find the literal text
"in|hill"



Reply to: