Bug 4520

Summary: grep -w fails when pattern is a strict substring of a word
Product: Busybox Reporter: anonym <anonym>
Component: Standard ComplianceAssignee: unassigned
Status: RESOLVED FIXED    
Severity: minor CC: anonym, busybox-cvs
Priority: P5    
Version: 1.19.x   
Target Milestone: ---   
Hardware: All   
OS: All   
Host: Target:
Build:

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