-2

I have a file static-nodes.json, which has the following content >>>

[

"enode://70399c3d1654c959a02b73acbdd4770109e39573a27a9b52bd391e5f79b91a42d8f2b9e982959402a97d2cbcb5656d778ba8661ec97909abc72e7bb04392ebd8@127.0.0.1:21000?discport=0&raftport=50000",

"enode://56e81550db3ccbfb5eb69c0cfe3f4a7135c931a1bae79ea69a1a1c6092cdcbea4c76a556c3af977756f95d8bf9d7b38ab50ae070da390d3abb3d7e773099c1a9@127.0.0.1:21001?discport=0&raftport=50001"

]

I want to add another enode >>>

"enode://56e81550db3ccbfb5eb69c0cfe3f4a7135c931a1bae79ea69a1a1c6092cdcbea4c76a556c3af977756f95d8bf9d7b38ab50ae070da390d3abb3d7e773099c1a9@127.0.0.1:21001?discport=0&raftport=50002"

But when I am trying to append it using the following command—>>>>>

Echo "enode to be appended " >> static-nodes.json

It is appended outside of the brackets as shown below

[

"enode://70399c3d1654c959a02b73acbdd4770109e39573a27a9b52bd391e5f79b91a42d8f2b9e982959402a97d2cbcb5656d778ba8661ec97909abc72e7bb04392ebd8@127.0.0.1:21000?discport=0&raftport=50000",

"enode://56e81550db3ccbfb5eb69c0cfe3f4a7135c931a1bae79ea69a1a1c6092cdcbea4c76a556c3af977756f95d8bf9d7b38ab50ae070da390d3abb3d7e773099c1a9@127.0.0.1:21001?discport=0&raftport=50001"

]

"enode://56e81550db3ccbfb5eb69c0cfe3f4a7135c931a1bae79ea69a1a1c6092cdcbea4c76a556c3af977756f95d8bf9d7b38ab50ae070da390d3abb3d7e773099c1a9@127.0.0.1:21001?discport=0&raftport=50001"

How should I fix this.?

Dharman
  • 30,962
  • 25
  • 85
  • 135
rest17
  • 25
  • 1
  • 6
  • 1
    `This post is hidden. It was deleted 19 mins ago by Bhargav Rao♦.` ? Was this question deleted? Please take your time and read [ask]. Please take your time and read [editing help](https://stackoverflow.com/editing-help). Prepend code and files with 4 spaces to make them visible nicely. `how should I fix this..?` Fix what exactly? You did append data to file and you succeeded in appending that data, so that's great. For editing json data use json-aware tool, like [jq](https://stedolan.github.io/jq/). Please create an [MCVE]. What output do you want? Please specify that. – KamilCuk Jul 23 '20 at 11:47

1 Answers1

0

Please have a look at how to add json object to json file using shell script

what you can do it

Option 1: create a temp json file using and then merge the temp json to nodes-json

toBeAppended = "enode to be appended"
echo "[ $toBeAppended ]" > tempNodes.json
jq -s add tempNodes.json static-nodes.json
 

Option 2. go with sed, awk, grep utilities

akhil132
  • 1
  • 2
  • Note, as given in the "Answer Well-Asked Questions" section of [How to Answer](https://stackoverflow.com/help/how-to-answer), that it's better to close a question you know to be duplicative as a duplicate than to answer it. That way folks get guided to a single canonical location where there's already been plenty of attention and effort given to providing the best possible answers. – Charles Duffy Jul 24 '20 at 22:28
  • Its not working shows error – rest17 Jul 29 '20 at 09:26