Grep -byte-offset does not return offset (Grep version 2.5.1)

Grep --byte-offset does not return offset (Grep version 2.5.1) Hello, I'm trying to get the position of a repeating line in a line using

the code:

 grep -b -o "pattern" 

On my server I use GNU grep version 2.14 and the code works fine. However, when I deploy the same code on another server that uses GNU grep version 2.5.1, the code does not work correctly. Despite the fact that there is a byte offset option. Any idea how to solve it.

Example:

the code:

 export string="abc cat mat rat cat bat cat fat rat tat tat cat" echo $string|grep -b -o "cat" 

Expected Result (and supported in grep 2.14):

 4:cat 16:cat 24:cat 44:cat 

But the same code with grep version 2.5.1 gives the following output:

 0:cat cat cat cat 

Please suggest ..

+4
source share
1 answer

This was a bug in grep, as some notes in her Changelog reference it:

  * 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 broken behavior. Patch #3769. 

Use later versions of at least 2.5.3 if they are already fixed.

+4
source

Source: https://habr.com/ru/post/1502185/


All Articles