[Toybox] grep corner cases
Rob Landley
rob at landley.net
Mon Aug 19 16:52:04 PDT 2013
On 08/19/2013 02:26:55 PM, Felix Janda wrote:
> Hi,
>
> I saw the comment in changeset 1017 on possible bugs in GNU grep.
>
> The failing tests are for me:
>
> testing "grep -vo" "grep -vo one input" "two\nthree\n"
> "onetwoonethreeone\n" ""
> testing "grep -Fx ''" "grep -Fx '' input" "one one one\n" "one one
> one\n" ""
> testing "grep -F -e blah -e ''" "grep -F -e blah -e '' input" "one
> one one\n" \
> "one one one\n" ""
>
> -o is a GNU extension making grep only output the matched parts of
> each
> matched line. So since -v inverts the set of all matched lines grep
> -vo
> should not output anything.
Does it invert the set of matched _lines_, or does it invert the match
criteria? I made it so that:
echo oneandtwoandthree | grep -ov
would produce:
one
two
three
(I pondered onetwothree but that's not how -o without -v works...)
The reason there are deviating test cases to consider is I'm not taking
"what gcc does" as an inherent definition of "the right thing to do".
> -F turns on fixed string matching so '' is no longer the empty regex
> which matches everything, but the empty string.
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html
-F Match using fixed strings. Treat each pattern specified as a string
instead of a regular expression. If an input line contains any of
the
patterns as a contiguous sequence of bytes, the line shall be
matched.
A null string shall match every line.
That implies that
echo one | grep -F -e walrus -e ''
Should match one, but with the gnu/dammit version it only does so
_without_ the -F. Or with -F and just one argument...
> Combined with -x IMO
> it should only match empty lines.
I asked the Austin guys how -F and -x interact. It's not obvious to me
from reading it.
Rob
1376956324.0
More information about the Toybox
mailing list