1

我的命令是:

[root@my /]# grep -lr --include=*version.php "$wp_version"/home/draka/www/
/home/draka/www/wp-content/version.php
/home/draka/www/wp-content/themes/version.php
/home/draka/www/wp-includes/version.php

我使用 sed 来查找特定的行:

[root@my /]# grep -lr --include=*version.php "$wp_version" /home/draka/www/ | xargs sed -n '7p'
$wp_version = '3.5';

每个文件夹的文件版本都不同:

  1. /home/draka/www/wp-content/version.php = $wp_version = '3.5.1';
  2. /home/draka/www/wp-content/themes/version.php = $wp_version = '3.5';
  3. /home/draka/www/wp-includes/version.php = $wp_version = '1.5';

我的问题是,我如何结合这 2 个输出?我想要的输出可能类似于:

/home/draka/www/wp-content/version.php = $wp_version = '3.5.1';

或者

/home/draka/www/wp-content/version.php -> $wp_version = '3.5.1';

非常感谢您的及时回复。谢谢你。

4

1 回答 1

1

省略-l, likegrep -r --include=*version.php wp_version /home/draka/www/会这样做。另请参阅man grep

-H, --with-filename
   Print the file name for each match.  This is the default when there is more
   than one file to search.
于 2013-05-03T13:45:24.027 回答