I am using grep to recursively look through files and pull out all strings matching a pattern. I want to print the file path: matched string.
-H should print the file path for each entry
-o should print just the matched string, omitting everything else on the line I don't want
-r recursive search.
grep -Hro [pattern] .
Most of the matches print with the filename, however a few just print the matched string. Are -H and -o mutually exclusive in that -o is trimming the filename? Sample Output:
The 4th foo match should also have a file associated with it, but it is not being printed.
I am getting behavior similar to this post, however I am using the -H flag, and the "/dev/null" solution does not work either.
$ grep --version
grep (BSD grep) 2.5.1-FreeBSD
After further exploring each match where the regex was not getting the file name, they all occur when two strings are matched on the same line. For example this text file
foo sometext foo
Anyone know a solution to get both matches to print a filename?