使用sed显示文件的确切位置

时间:2013-05-03 12:53:07

标签: linux sed

我的命令是:

[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';
  4. 我的问题是,我如何结合这两个输出?我想要的输出可能是这样的:

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

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

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

1 个答案:

答案 0 :(得分:1)

省略-l,就像grep -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.