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
  • 86,927
  • 13
  • 98
  • 148
liv2hak
  • 13,641
  • 48
  • 139
  • 250

3 Answers3

2

You can use

awk '{sub('/^{/', "{\n", $0); sub('/}$/', "\n}", $0); gsub('/,/', ",\n", $0); print;}' filename
a5hk
  • 7,064
  • 2
  • 25
  • 36
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
  • 1,954
  • 11
  • 12
0

This might work for you (GNU sed):

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