Currently, I have
grep -irl $schema $WORKDIR/ | xargs sed -i 's/'"$schema"'/EXI1/gI'
which doesn't work for filenames with spaces.
Any ideas, how to search and replace recursively for all files?
Thanks
Add the -Z
(aka --null
) flag to grep
, and the -0
(also aka --null
) flag to xargs
.
This will output NUL terminated file names, and tell xargs
to read NUL terminated arguments.
eg.
grep -irlZ $schema $WORKDIR/ | xargs -0 sed -i 's/'"$schema"'/EXI1/gI'
find with sed should work:
find $WORKDIR/ -type f -exec sed -i.bak "s/$schema/EXI1/gI" '{}' +
OR
find $WORKDIR/ -type f -print0 | xargs -0 sed -i.bak "s/$schema/EXI1/gI"