Where you use:
sed -i 's C:\ /root/ g'
you're using the s
command with a space character separating the different parts of the command, which is unusual, but completely valid. When you precede your separator character with a backslash, though, it's not treated as a separator, but as part of the argument itself.
The problem you have here is that the backslash in C:\
is escaping the space in the middle, so s
never finds the end of the replacement (which is now g
) and complains that the command is unfinished, as you saw.
At the least, you need to escape the backslash itself with another backslash:
sed -i 's C:\\ /root/ g'
This will work, although replacing the spaces with another character might be clearer.
As for your use of xargs
and subdirectories - xargs
isn't required here, and find
can do it, including handling files in subdirectories, on its own. Use:
find ../ \( -name "*.xml" -o -name "*.conf" \) -exec sed -i -e 's|C:\\|/root/|g' '{}' +
to have find
run the sed
command itself with all the filenames it finds. The filenames are inserted in place of the {}
, and +
means find
will minimise the number of times it runs the command.
-execdir
may be better than -exec
for certain security reasons outlined in the find
man page; it is a non-standard extension, but as you seem to be using GNU tools it should be there for you if you need it.