I want to recursively find files in my source tree by contents. I've tried the following using grep:
$ grep -rn printf | grep %s | grep bcm_errmsg\(rv\)
This returns me every line as I wanted but now, I would like to get the filename of each file that matches, so I changed it to:
$ grep -rn printf | grep %s | grep -l bcm_errmsg\(rv\)
but instead of printing the filenames, I only get
(standard input)
printed to stdout. How do I fix this to get each filename & path (to use sed on it)?
What I want to do: Find every file with printf lines that also contain %s and bcm_errmsg(rv) and then apply the following sed command to the files found:
sed -i 's/%s/%d/g; s/bcm_errmsg(rv)/rv/g;'
printf,%sandbcm_errmsg(rv)is unambiguous, you should be able to construct a single regular expression that matches all three in a singlegrep. In fact if you end goal is to edit the matching files insed, I doubt you needgrepat all - just letseddo the pattern matchinggrep2.27, the filename is automatically prefixed with option-r. Latergrepping behind the pipe doesn't remove that path, so yoursedknows everything before the first:is the path.sedcommands to every line in files that contain the matching text, or only to the matching lines themselves?