Reputation: 318
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
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