1

I'm writing a linux script, which is to replace a string for a file. Here is my script:

#!/bin/sh
var=./video/example.mp4
`sed -i '' 's/sceneFilePath:.*/sceneFilePath: "$var",/g' test`

In the file named test, there is a line like this:

sceneFilePath: "t.mp4",

What I need is to replace this line with the line below:

sceneFilePath: "./video/example.mp4",

It means that things between double quotes should be replaced by the $var.

However when I execute my script, I get sceneFilePath: "$var",.

I've read this answer: Replace a string in shell script using a variable

However, I get an error:

sed: 1: "s/sceneFilePath:.*/scen ...": bad flag in substitute command: 'v'

Community
  • 1
  • 1
Yves
  • 11,597
  • 17
  • 83
  • 180
  • 1
    Use different delimiters in sed which don't appear in you filepaths/names. `s#somthing#$var#`. You probably don't need to `g` flag either. You also don't need to run it in a subshell using `\`\``. You can run the command as is. – 123 May 09 '17 at 10:41

1 Answers1

0
var='.\/video\/example.mp4'
sed -i '' "s/sceneFilePath:.*/sceneFilePath: \"$var\",/g" test

Else:

var='./video/example.mp4'
sed -i '' "s#sceneFilePath:.*#sceneFilePath: \"$var\",#g" test
chepner
  • 497,756
  • 71
  • 530
  • 681
Arjun Mathew Dan
  • 5,240
  • 1
  • 16
  • 27