I am trying to substitute name=src.
with name=Web/
in my xml file using the sed
command:
sed -i 's/name=src\./name=WebUi\//g' coverage.xml
but it gives an error.
Can anyone please provide an idea on the sed
command?
I am trying to substitute name=src.
with name=Web/
in my xml file using the sed
command:
sed -i 's/name=src\./name=WebUi\//g' coverage.xml
but it gives an error.
Can anyone please provide an idea on the sed
command?
Use:
sed 's/name=src/name=Web/g' filename.txt
When /
appears as part of the text, whether in the regex or replacement, use a character other than /
in the s///
notation (I chose |
, but you can use any character that doesn't appear in the regex or replacement; a control character such as Control-A can often be effective and safe):
sed command sed -i 's|name=src\.|name=WebUi/|g' coverage.xml
Note that the -i
option written like that only works with GNU sed
; with BSD or macOS sed
, you'd need -i ''
instead. Using -i.bak
works the same with both but leaves a backup file that should be removed.
It always worries me when I see people with broken sed
scripts doing an in-place alter. You shouldn't think of using the -i
option until you're confident the script works.
On review, I'm surprised that the original 's/name=src\./name=WebUi\//g'
didn't work — the backslash before the slash should have been correct.