I'm getting an error with the following
find . -name "*" -type f | xargs grep -l "xyz" | sed -i '' 's/'${line}'/'${rep}'/g'
sed: -i may not be used with stdin
what's gone wrong?
Asuming that you're trying to sed something only in the files that contain xyz, you will have to xargs again
find . -name "*" -type f | xargs grep -l "xyz" |xargs sed -i "s/'${line}'/'${rep}'/g"
-i
is for inline file editing and you are just piping find command's output to sed
in stdin hence that error shows up.
Try this find command
instead:
find . -name "*" -type f -exec sed -i '' "s/${line}/${rep}/g" '{}' \;
PS: -name "*"
can also be skipped here.
When we are using the find command we can't connect the output with the pipe( | ). So you can use the -exec with find command to execute more commands.