Issue
trying to find all files with this text "david_now" and replace with this "david_old"
grep -r "david_now" | sed -i 's"david_now"david_old"g
'
It fails on some files and stops example:
sed no input files
BRF/Test_page.mujebr3.brf: binary file matches
Solution
You're passing the output of grep -- a list of files -- as input to sed. If you want sed to actually operate on those files, you'll need to use the xargs
command, as in:
grep -rl "david_now" | xargs sed -i 's"david_now"david_old"g'
This will mostly work, although if you have filenames that contain whitespace you'll need to modify grep to use a NUL seperator between filenames:
grep -rlZ "david_now" | xargs -0 sed -i 's"david_now"david_old"g'
Answered By - larsks Answer Checked By - Clifford M. (WPSolving Volunteer)