I've been trying to create a script that would replace every occurence of C:\ in two different types of file by /root.My arborescence looks like :- Batch  - Place of the script- Conf  - Appli1    - File1.xml    - File2.xml    - ...  - Appli2    - File1.xml    - File2.xml    - ...  - ...- Info  - File1.conf  - File2.conf  - ...My script is like so in /Batch :#/bin/bashfind ../ -name *.xml -o name *.conf -print | xargs sed -i 's C:\ /root/ g'But, I have an error on the sed part, which says that at character 14: command 's' unfinishedWhy is that so?
Replace a backslash with sed
sed;quoting
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.