I'm doing some text manipulation and I want to add a property (at the end) to a jsonan object named "object" that is inside a jsonconfiguration file
e.g
.
.
object = {
"one": "one",
"two": "two",
}
.
.
Should become
.
.
object = {
"one": "one",
"two": "two",
"three": "three",
}
.
.
This is my attempt, but i'm wondering if there is a cleaner way of doing things.
#find line for last property
line=$(grep -n "$(awk "/object/{f=1;next} /}/{f=0} f" file.txt | tail -n 1)" file.txt | awk -F : '{ print $1 }')
content='\"three\" = \"three\"'
awk 'NR=='$((line + 1))' {print "\t '"$content"'"} 1' file.txt > file.temp && mv file.temp file.txt