Grep --byte-offset 不返回偏移量(Grep 2.5.1 版)

use*_*933 6 bash grep offset

Grep--byte-offset不返回偏移量(Grep 版本 2.5.1) 嗨,我正在尝试使用

代码:

grep -b -o "pattern"
Run Code Online (Sandbox Code Playgroud)

在我的服务器中,我使用的是 GNU grep 2.14 版,代码运行良好。但是,当我在使用 GNU grep 2.5.1 版的不同服务器中部署相同的代码时,代码无法正常工作。即使字节偏移选项在那里可用。任何想法如何解决它。

例子:

代码:

export string="abc cat mat rat cat bat cat fat rat tat tat cat"
echo $string|grep -b -o "cat"
Run Code Online (Sandbox Code Playgroud)

预期输出(并在 grep 2.14 中支持):

4:cat
16:cat
24:cat
44:cat
Run Code Online (Sandbox Code Playgroud)

但是与 grep 版本 2.5.1 相同的代码给出了以下输出:

0:cat
cat
cat
cat
Run Code Online (Sandbox Code Playgroud)

请建议..

kon*_*box 5

这是 grep 中的一个错误,因为它的更新日志中的一些注释提到了它:

    * src/grep.c (nlscan): Make this function more robust by removing
      the undocumented assumption that its "lim" argument points
      right after a line boundary.  This will be used later to fix
      --byte-offset's broken behavior.  Patch #3769.
Run Code Online (Sandbox Code Playgroud)

使用似乎已经修复的更高版本(至少 2.5.3)。