Add a new role to a Chef .json file with Sed
I have a typical .json file for Chef e.g. servername.json { "name": "myserver123", "chef_environment": "test", "run_list": [ "role[base-pkg]", "role[interesting_stuff]", "role[user_apps]" ] } What I would like to do is use a "one liner" to add a new role after the last role found in the file. Since I never know what roles or how many are in a file i thought to search for the final closing "]" bracket and add the new role above that. I tried the following: tac servername.json | sed -i '0,/\]/a "role[My_New_Role]"' thinking that this would find the (now) first "]" and add the new line after it.