ikask
ikask

Reputation: 318

how to use sed to replace values in json file variable value

I need to use sed to modify the 3rd line in my.json file as line shown below.

How do I replace a changing key value( this example shows "group-1") with the variable value that is assigned to $username?

    "name": "group-1",

Upvotes: 4

Views: 10037

Answers (1)

ntshetty
ntshetty

Reputation: 1305

You can replace like below

Linux

 sed -i 's/\"name\":.*/\"name\": '${username}'/g' "/path/to/my.json"

MacOS

   sed -i "" 's/\"name\":.*/\"name\": '${username}'/g' "/path/to/my.json"

Upvotes: 7

Related Questions