0

I need to replace ../ with ./ from below line.

<html xmlns:og="http://test.org/schema/"  xmlns:website="../test/ns/website" >

But when use the command

sed -i 's+../+./+g' ./*

The file content changed to

<html xmlns:og="htt.//test.o./sche./" xmlns:website="./te././website" >

What could be the problem.

CodeDezk
  • 1,230
  • 1
  • 12
  • 40
  • 4
    Possible duplicate of [Search and replace with sed when dots and underscores are present](https://stackoverflow.com/q/6123915/608639), [Use sed with variable that contains dot](https://stackoverflow.com/q/39659946/608639), [Escape a string for a sed replace pattern](https://stackoverflow.com/q/407523/608639), [What characters do I need to escape when using sed in a sh script?](https://unix.stackexchange.com/q/32907) and friends. – jww Jul 25 '19 at 17:09

1 Answers1

2

This should do:

echo "<html xmlns:og="http://test.org/schema/"  xmlns:website="../test/ns/website" >" | sed 's|\.\./|./|g'
<html xmlns:og=http://test.org/schema/  xmlns:website=./test/ns/website >

You need to escape the . or else it mean any character.

This should work as well: sed 's+\.\./+./+g'

Jotne
  • 40,548
  • 12
  • 51
  • 55