0

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?

3 Answers 3

2

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"
1

-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.

1

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.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.