I have a file in the format below. Can anyone convert it in columns? I have tried the awk command below but it creates more that 4 columns if one customer has multiple hostnames.
awk '/"customer_name":/{if (x)print x;x="";}{x=(!x)?$0:x","$0;}END{print x;}' filename
Input:
customer_name: "abc"
"HostName": "tm-1"
"LastDayRxBytes": 0
"Status": "offline"
"HostName": "tm-2"
"LastDayRxBytes": 0
"Status": "offline"
"HostName": "tm-3"
"LastDayRxBytes": 0
"Status": "offline"
"HostName": "new-va-threat-01"
"LastDayRxBytes": 0
"Status": "offline"
customer_name: "xyz"
"HostName": "tm-56"
"LastDayRxBytes": 10708747
"Status": "ok"
customer_name: "def"
customer_name: "uvw"
"HostName": "tm-23"
"LastDayRxBytes": 34921829912
"Status": "ok"
customer_name: "new cust"
"HostName": "tm-1-3"
"LastDayRxBytes": 33993187093
"Status": "ok"
customer_name: "a12 d32 ffg"
customer_name: "bcd abc"
customer_name: "mno opq"
customer_name: "abc dhg pvt ltd."
"HostName": "tm-10"
"LastDayRxBytes": 145774401010
"Status": "ok"
"HostName": "tm-ngtm-13"
"LastDayRxBytes": 150159680874
"Status": "ok"
"HostName": "new-ngtm-11"
"LastDayRxBytes": 207392526747
"Status": "ok"
"HostName": "old-ngtm-06"
"LastDayRxBytes": 17708734533
"Status": "ok"
"HostName": "tm-08"
"LastDayRxBytes": 559289251
"Status": "ok"
"HostName": "tm-12"
"LastDayRxBytes": 534145552271
"Status": "ok"
I want it to be printed in column and rows as:
Column 1 Column 2 Column 3 Column 4
CustName Host Last RX Status
abc tm-1 0 offline
abc tm-2 0 offline
abc tm-3 0 offline
abc new-va-threat-01 0 offline
xyz tm-56 10708747 ok
def
uvw tm-23 34921829912 ok
new_cust tm-1-3 33993187093 ok
a12 d32 ffg
acd abc
mno opq
abc dhg pvt ltd. tm-10 145774401010 ok
abc dhg pvt ltd. tm-ngtm-13 150159680874 ok
abc dhg pvt ltd. new-ngtm-11 207392526747 ok
abc dhg pvt ltd. old-ngtm-06 17708734533 ok
abc dhg pvt ltd. tm-08 559289251 ok
abc dhg pvt ltd. tm-12 534145552271 ok
:or:<blank>? How about an escaped"(e.g.\"or"")?