0

I have information as given below in a text file.

{"00:00:00:00:00:00:02:03":[{"controllerId":"onos-primary"}],"00:00:00:00:00:00:02:02":[{"controllerId":"onos-primary"}],"00:00:00:00:00:00:02:01":[{"controllerId":"onos-primary"}],"00:00:00:00:00:00:02:06":[{"controllerId":"onos-primary"}],"00:00:00:00:00:00:02:05":[{"controllerId":"onos-primary"}],"00:00:00:00:00:00:02:04":[{"controllerId":"onos-primary"}]}

I want that information to be like this.

{
"00:00:00:00:00:00:02:03":[{"controllerId":"onos-primary"}],
"00:00:00:00:00:00:02:02":[{"controllerId":"onos-primary"}],
"00:00:00:00:00:00:02:01":[{"controllerId":"onos-primary"}],
"00:00:00:00:00:00:02:06":[{"controllerId":"onos-primary"}],
"00:00:00:00:00:00:02:05":[{"controllerId":"onos-primary"}],
"00:00:00:00:00:00:02:04":[{"controllerId":"onos-primary"}]
}

How can I acheieve this using Linux commandline.? I am willing to use awk or sed or simple bash

Andy Lester
  • 91,102
  • 13
  • 100
  • 152
liv2hak
  • 14,472
  • 53
  • 157
  • 270

3 Answers3

2

You can use

awk '{sub('/^{/', "{\n", $0); sub('/}$/', "\n}", $0); gsub('/,/', ",\n", $0); print;}' filename
a5hk
  • 7,532
  • 3
  • 26
  • 40
1

My i suggest python?

python -m json.tool < file.json 

And with syntax-highlighting:

python -m json.tool < file.json | highlight --syntax js -O xterm256
phylax
  • 2,034
  • 14
  • 13
0

This might work for you (GNU sed):

sed -r 's/\{(.*)\}/{\n\1\n}/;s/,/&\n/g' file
potong
  • 55,640
  • 6
  • 51
  • 83