Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Why in the following:

echo this is a line. | grep -o -E "[a-z]+\."

The result is line. and not this is a line.?

There is no word boundary or any other restriction on the regex.

share|improve this question
up vote 5 down vote accepted

[a-z] only matches the characters a to z. they do not match the space character. when you want to match also the space character you have to explicitly say so: [a-z ].

share|improve this answer
[a-z] only matches the characters a to z. Yes I understand.But why in this case it is line that matches and not this or is or this is a line? – Jim Jul 8 '13 at 5:59
because your pattern has a dot in the end. line. is the only part that matches "at least one of a to z followed by a dot". – lesmana Jul 8 '13 at 8:04

The -o option instructs grep to limit the output to just that part of the line which matches the pattern.

Rerun the command without -o and the result will indeed be

this is a line.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.