grep的--byte偏移不返回偏移量(grep的版本2.5.1) [英] Grep --byte-offset not returning the offset (Grep version 2.5.1)

查看:175
本文介绍了grep的--byte偏移不返回偏移量(grep的版本2.5.1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

grep的 - 字节偏移未返回偏移量(grep的版本2.5.1)

我试图用得到一个重复的字符串的一条线的位置

code:

 的grep -b -o模式

在我的服务器我使用GNU的grep版本2.14和code是工作的罚款。然而,当我部署在该用的是GNU的grep版本2.5.1 code不能正常工作在不同的服务器相同的code。即使字节偏移选项可用那里。不知道如何解决它。

例如:

code:

 出口字符串=ABC猫鼠垫猫蝙蝠猫胖老鼠达达猫
回声$字符串| grep的-b -o猫

期望输出(在grep的2.14支持):

  4:猫
16:猫
24:猫
44:猫

但同样code使用grep版本2.5.1是给下面的输出:

  0:猫



请建议..


解决方案

这是grep的一个bug在其更新日志的一些注意事项是指它:


  * SRC / grep.c(nlscan):使此功能通过移除更稳健
      无证假设它的廉的争论点
      之后行边界。这将在以后用于修复
      --byte偏移的破碎行为。补丁#3769。


使用它似乎已经固定更高版本至少2.5.3。

Grep --byte-offset not returning the offset (Grep version 2.5.1) Hi, I am trying to get the position of a repeated string in a line using

Code:

grep -b -o "pattern"

In my server I am using GNU grep version 2.14 and the code is working fine. However when I am deploying the same code in a different server which is using GNU grep version 2.5.1 the code is not working properly. Even though the byte offset option is available there. Any idea how to solve it.

Example:

Code:

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

Expected output (and supported in grep 2.14):

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

But same code with grep version 2.5.1 is giving the following output:

0:cat
cat
cat
cat

Please suggest..

解决方案

It was a bug in grep as some notes in its Changelog refers to 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's broken behavior.  Patch #3769.

Use later versions at least 2.5.3 where it seems fixed already.

这篇关于grep的--byte偏移不返回偏移量(grep的版本2.5.1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆