【问题标题】:Why theses both egrep search don’t return the same result?为什么这两个 egrep 搜索都不返回相同的结果?
【发布时间】:2015-10-10 23:30:21
【问题描述】:

我想了解为什么使用 include 参数它不会搜索目标文件 Identification.php。


使用 include 参数:

admin@server:/filer/www/website/httpdocs$ egrep -Rns --include=*.php "deleteTemp" *
identification.php-sed:61:  $deleteTemp = " DELETE FROM ".$table_name."
identification.php-sed:64:  $execTemp   = @mysql_query ( $deleteTemp );

没有:

admin@server:/filer/www/website/httpdocs$ egrep -Rns "deleteTemp" *
identification.php:61:  $deleteTemp = " DELETE FROM ".$table_name."
identification.php:64:  $execTemp   = @mysql_query ( $deleteTemp );
identification.php-sed:61:  $deleteTemp = " DELETE FROM ".$table_name."
identification.php-sed:64:  $execTemp   = @mysql_query ( $deleteTemp );

我也尝试了包含模式的引号,结果是一样的。

【问题讨论】:

  • 您确定第一个返回来自.php-sed 文件的条目吗?我原以为它会从.php 文件和not .php-sed 文件返回结果。由于identification.php-sed 与*.php 模式/glob 不匹配。
  • 是的,我敢肯定,正是因为如此,我才感到惊讶,反过来应该更合乎逻辑……但是我会在超级用户网站上发帖,但我失败了:D
  • 最奇怪的是第一个请求末尾的点通配符结果相反!
  • 很奇怪,我做了一个测试,使用--include=*.php 我得到的只是匹配的*.php 文件。最好指出您正在使用的 grep 版本。
  • 我的版本:Ubuntu 12.04 上的 grep (GNU grep) 2.10

标签: bash ubuntu grep include-path


【解决方案1】:

我认为这是因为你的模式正在被 shell 解释,试试:

egrep -Rns --include=\*.php "deleteTemp" *

对了,你知道ag吗?

【讨论】:

  • 没有。由于没有与--include=\*.php 匹配的文件,因此shell 保留--include=\*.php 原样。
  • 是的,这与我尝试过的完全一样。我刚刚读到 ack 在这里搜索我的回复,但我无法在这台机器上安装任何东西。
  • 我复制了一份 Identification.php 并将其重命名为 Identification2.php.foo 并使用在这个新文件中找到的相同包含进行搜索...
  • 从父文件夹搜索并定位该文件夹也会显示正确的结果:admin@server:/filer/www/website$ egrep -Rns --include=*.php "deleteTemp" httpdocs httpdocs/ identity.php:61: $deleteTemp = " DELETE FROM ".$table_name." httpdocs/identification.php:64: $execTemp = @mysql_query ($deleteTemp);
  • 伙计们,它适用于所有文件,只需省略 * 标记! egrep -Rn --include=.php 'deleteTemp' *
猜你喜欢
  • 2019-01-14
  • 2018-11-19
  • 2023-03-22
  • 1970-01-01
  • 1970-01-01
  • 2019-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多