다음 데이터가 포함된 CSV 파일이 있습니다.
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
다음 형식의 출력이 필요합니다.
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,
등..기본적으로 키(열 이름):값으로 출력이 필요합니다.
답변1
$ awk -F, 'NR==1{for(i=1;i<=NF;i++)Arr[i]=$i;next}{printf("%s,",$1);for(j=2;j<=NF;j++){printf("%s:%s,",Arr[j],$j)}printf("\n")}' filename.csv
tablespace,DBNAME:MRETF,tblsps_name:RERETOSB15_DATA,Cur_size:51200,Max_size:45600,Used:14284,Free:31316,Percentage:31,
tablespace,DBNAME:MRETF,tblsps_name:SPOTLIGHT_DATA,Cur_size:500,Max_size:2000,Used:259,Free:1741,Percentage:13,
tablespace,DBNAME:MRETF,tblsps_name:DDLAUDITING,Cur_size:25,Max_size:25,Used:2,Free:23,Percentage:8,
출력에 DBNAME이 없는 이유는 무엇입니까?