Bug 4520 - grep -w fails when pattern is a strict substring of a word
Summary: grep -w fails when pattern is a strict substring of a word
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Standard Compliance (show other bugs)
Version: 1.19.x
Hardware: All All
: P5 minor
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-23 20:14 UTC by anonym
Modified: 2014-02-27 13:57 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description anonym 2011-11-23 20:14:28 UTC
It seems whenever busybox grep -w finds the pattern as a strict substring of a word but then sees that it's not enclosed by symbols that delimit words, the whole line is discarded. As a result, grep won't find the pattern when it occurs as a word later in the line, and hence won't match the line.

Examples:

# the good cases that work as expected:
echo "a" | busybox grep -w a
a
echo "b,a" | busybox grep -w a
b,a

# the bad cases which should match but doesn't:
echo "ab,a" | busybox grep -w a
<no match>
echo "ba,a" | busybox grep -w a
<no match>
echo "bab,a" | busybox grep -w a
<no match>

Shouldn't `grep -w ${X}` be equivalent to `grep -e "\<${X}\>"` (the latter works fine in busybox's grep)? At least that seems to be the case in GNU grep, and is explicitly the case in BSD grep according to its manual.
Comment 1 Denys Vlasenko 2014-02-27 13:57:22 UTC
Fixed in git:

commit 83e49ade5724f5b3744660e45179461fe2a1b0f8
Author: Denys Vlasenko <vda.linux@googlemail.com>
Date:   Thu Feb 27 14:56:12 2014 +0100

    grep: fix -w match if first match isn't a word, but second is