0

On at least CentOS systems and previous versions of Fedora, I could run the following command and get a list of files with the corresponding grep matches:

$ find -name "version.php" -type f | xargs grep "^\$wp_version" site.com/wp-includes/version.php:$wp_version = '4.7.3';

Apparently though on at least Fedora 22 and newer, running that same command no longer includes the path and filenames:

find -name "version.php" -type f | xargs grep "^\$wp_version" $wp_version = '4.7.3';

I know I can include -l to show just the path, but is there a way to include the path without dropping the match? I don't see anything in the man file.

1 Answers1

2

CentOS/Fedora, so assuming GNU grep, which has the following switch:

-H, --with-filename
   Print the file name for each match.  This is the default 
   when there is more than one file to search.

In other words, the difference in behaviour might be just that in the first case, find catches more than one file, making grep list the file names. If it matches only one file in the second case, the names would be missing.

So, add -H manually to force it.

ilkkachu
  • 138,973
  • thanks, any idea why that is not in the man grep? By the way, it works without the -H on CentOS, it's Fedora where it wasn't working. – Michael VanDeMar Mar 17 '17 at 02:10
  • Or you could just slip in /dev/null to grep to make the filename+match to always be printed: find ... | xargs grep version /dev/null –  Mar 17 '17 at 08:08