-1

I have one file i need to replace below src string to dst string with below values.

src="59/291259.wav"
dest="58/291258.wav"

echo "source string= $src    replacement string= $dest"

I'm trying below sed command, but getting below errors. could anyone help on thihs.

sed -i "s/$src/$dest/g" test.xml

Error: sed: -e expression #1, char 19: unknown option to `s'

Muldec
  • 4,641
  • 1
  • 25
  • 44
  • 1
    This question is now cross-posted on Unix+Linux: https://unix.stackexchange.com/questions/534077/replace-one-string-to-another-string-having-forward-slash-in-both-the-string-u – John1024 Aug 06 '19 at 05:50

2 Answers2

3

Sed is getting confused by the slashes in your strings. Try using a different delimiter:

sed -i "s|$src|$dest|g" test.xml
Beta
  • 96,650
  • 16
  • 149
  • 150
-1

If using Bash, then replace the slashes with backslash-prefixed ones:

sed -i "s/${src//\//\\/}/${dest//\//\\/}/g" test.xml

This is more robust than trying to find an alternate delimiter that "can't occur" within the variables.

You may want to replace other sed-significant characters, such as & within $dest, and \ itself in both.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103