我的命令是:

[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';

每个文件夹的文件版本不同:
/主页/draka/www/wp content/version.php=$wp_version='3.5.1';
/home/draka/www/wp content/themes/version.php=$wp_version='3.5';
/home/draka/www/wp includes/version.php=$wp_version='1.5';
我的问题是,我如何将这两个输出结合起来?我想要的输出可能是:
/home/draka/www/wp-content/version.php = $wp_version = '3.5.1';


/home/draka/www/wp-content/version.php -> $wp_version = '3.5.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.

关于linux - 使用sed显示文件的确切位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16359410/

10-15 01:41