I have an input text file in unix with this kind of data.
Event_date:20190512044638
Error_code:5858
Event_type:GPRS data
Duration:772
Missing_provider_id:46009
Event_date:20190512044638
Error_code:780678
Event_date:20190512064535
Error_code:5858
Event_type:GPRS data
Duration:2172
Missing_provider_id:722310
i want this data to be in this output format:
Event_date Error_code Event_type Duration Missing_provider_id
20190512044638 5858 GPRS data 772 46009
20190512044638 780678
20190512064535 5858 GPRS data 2172 722310
I tried a combination of awk and sed commands, but didn't work out. How can i achieve this output?
Event_date:20190512044638
Error_code:5858
Event_type:GPRS data
Duration:772
Missing_provider_id:46009
Event_date:20190512044638
Error_code:780678
Event_date:20190512064535
Error_code:5858
Event_type:GPRS data
Duration:2172
Missing_provider_id:722310
i want this data to be in this output format:
Event_date Error_code Event_type Duration Missing_provider_id
20190512044638 5858 GPRS data 772 46009
20190512044638 780678
20190512064535 5858 GPRS data 2172 722310
here is another one
no 2D arrays, but needs to scan the file twice to get all header info in order not to keep any data in memory, but to process the lines as they appear.
This
awk
may do: (tab separated fields)PS this will fail if on field is missing, all need to come in order.
A more generic solution:
NR==1 {print $1,$3,$5,$7,$9}
can be set to some static header likeNR==1 {print "F1","F2","F3","F4","F5"}
etcUsing GNU awk and 2D arrays:
Output: