Bug 95936 - egrep(1) misparses multiline parenthetical grouping
Summary: egrep(1) misparses multiline parenthetical grouping
Status: Closed Works As Intended
Alias: None
Product: Base System
Classification: Unclassified
Component: gnu (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-17 17:30 UTC by David C Lawrence
Modified: 2017-06-19 23:14 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David C Lawrence 2006-04-17 17:30:22 UTC
``egrep (GNU grep) 2.5.1-FreeBSD'' will not correctly see the closing
parenthesis of a grouping if it is not on the same line as the opening
parenthesis.  ``egrep (GNU grep) 2.4d'' did not have this problem.

How-To-Repeat: echo hi | egrep '(
hi)'
Comment 1 Kyle Evans freebsd_committer freebsd_triage 2017-04-20 15:07:20 UTC
Hi (delayed response),

This is actually intended behavior. It's not so much that it doesn't correctly see it, it's that newlines are pattern delimiters, so this is actually broken into two different patterns: '(', and 'hi)'. To verify, check:

$ printf "hi\nthere" | egrep -o "hi
er"
hi
er
# Correct

This is probably dual purpose:

1. Maintains consistency with file-read patterns (-f)
2. grep is inherently line-oriented, thus making it nonsensical to actually match on newlines.
Comment 2 David C Lawrence 2017-06-19 22:45:26 UTC
Good point.  I agree that it probably shouldn't be classified as a bug.  I don't even remember what exactly led me to discover the problem in some script that I had, other than the obvious thing that I upgraded.  The most remarkable thing to me was the difference between versions, that what had previously been accepted was now returning an error.  I see little reason not to close this, so I will.  (I'm unclear on what the difference between Working as Intended and Not a Bug are though, so apologies if I picked wrongly.)
Comment 3 Glen Barber freebsd_committer freebsd_triage 2017-06-19 23:14:52 UTC
(In reply to David C Lawrence from comment #2)
> (I'm unclear on what the difference between
> Working as Intended and Not a Bug are though, so apologies if I picked
> wrongly.)

Maybe we need a "Works as Written" resolution.  :)