Reputation: 51
Apologies if this has been covered before, I had a search but couldn't find anything. I realise this is probably a simple error, but I'm currently learning UNIX.
I've been trying to do a sed substitution but every time I've tried the command just seems to print out the files and not substitute anything?
The command in question is:
find . -name 'config.xml' -exec sed 's/<name>development<\/name>/<name>releases<\/name>/g' {} \;
After I run this command, if I try to find and grep for <name>development<\/name>
it still returns results. Why?
Any help would be appreciated! Thanks.
Upvotes: 2
Views: 87
Reputation: 24739
This is because you're not actually editing the file--just printing the edited version to stdout
. Use sed's -i
flag:
-i[SUFFIX]
--in-place[=SUFFIX]
This option specifies that files are to be edited in-place. GNUsed
does this by creating a temporary file and sending output to this file rather than to the standard output.(1).
So:
find . -name 'config.xml' -exec sed -i 's/<name>development<\/name>/<name>releases<\/name>/g' {} \;
You can also use a different character besides /
if you don't want to have to escape them:
find . -name 'config.xml' -exec sed -i 's@<name>development</name>@<name>releases</name>@g' {} \;
Upvotes: 2