grep and anchoring

Warren Block wblock at wonkity.com
Sun Jun 26 18:44:50 UTC 2016


On Sun, 26 Jun 2016, Matthew Seaman wrote:

> On 26/06/2016 15:44, Daniël de Kok wrote:
>> Note the anchoring (^), the pattern should only match any four characters at the beginning of the line, so the expected output is ‘1234’ and nothing more. ‘ 123' and '4 12' are not at the beginning of the line and should consequently not be printed to stdout.
>>
>> For comparison, the output of a recent GNU grep:
>>
>>>> %  echo "1234 1234 1234" | grep -o '^....'
>> 1234
>>>
> You are completely correct -- this is a bug in grep(1) on FreeBSD.  In
> all current releases including the upcoming 11.0-RELEASE grep is
> actually GNU grep version 2.1.5.  However, the same bug occurs in
> bsdgrep(1):
>
> % echo 1234 1234 1234 | bsdgrep -o '^....'
> 1234
> 123
> 4 12

Yay for compatibility! :)


More information about the freebsd-questions mailing list