Badri M
Badri M

Reputation: 25

Script for changing CSV into Key Value (KV) format

I have a CSV file with data as below:

row_identifier,DBNAME,tblsps_name,Cur_size,Max_size,Used,Free,Percentage
tablespace,MRETF,RERETOSB15_DATA,51200,45600,14284,31316,31
tablespace,MRETF,SPOTLIGHT_DATA,500,2000,259,1741,13
tablespace,MRETF,DDLAUDITING,25,25,2,23,8

I want the output in the following format:

tablespace,MRETF,tblsps_name:RERETOSB15_DATA,Cur_size:51200,Max_size:45600,Used:14284,Free:31316,Percentage:31
tablespace,MRETF,tblsps_name:SPOTLIGHT_DATA,Cur_size:500,Max_size:2000,Used:259,Free:1741,Percentage:13

and so on..

Is this possible to get the output like the above key:value format?

Upvotes: 1

Views: 175

Answers (1)

lojza
lojza

Reputation: 1891

Next time at least pretend that you tried something ;-)

awk -F"," 'FNR > 1 {print $1","$2",tblsps_name:"$3",Cur_size:"$4",Max_size:"$5",Used:"$6",Free:"$7",Percentage:"$8}' your.csv

-F"," is field separator, FNR > 1 skip first header line, $1 is first column and so on

Upvotes: 1

Related Questions