简体   繁体   English

如何在Linux中将相同的标头数据附加到一个标头

[英]how to append same header data to one header in linux

my data is seperated by comma delimiter So by talking value before comma as main header column and if the same header occured somewhere elese, apped data into one header by placing open and closed flower brackets 我的数据用逗号定界符分隔,因此,在逗号之前将值称为主标题列,如果相同的标题出现在elese某处,则通过放置开和闭花括号将数据绑定到一个标题中

Please consider my example for better understading 请考虑我的例子,以更好地理解

Input file data 输入文件数据

19,66:BILL
19,34
19,02
21,:0
21,:0
21,:1
21,37
26,:19
26,87
27,35
31,77
31,12
31,202

Output file data 输出文件数据

19,{66:BILL}{34}{02}
21,:{0}{:0}{:1}
21,37
26,{:19}{87}
27,35
31,{77}{12}{102}

A solution using awk 使用awk的解决方案

$ awk -F, '{a[$1]=a[$1]"{"$2"}"} END{for (i in a) print i FS a[i]}' input.csv

Assuming that the input file contains two columns only, the script constructs an array a by appending the values $2 of all rows with the same index $1 into the same element a[$1] 假设输入文件仅包含两列,则脚本通过将具有相同索引$1的所有行的值$2附加到同一元素a[$1]构造数组a

input.csv input.csv

19,66:BILL
19,34
19,02
21,:0
21,:0
21,:1
21,37
26,:19
26,87
27,35
31,77
31,12
31,202

output 输出

19,{66:BILL}{34}{02}
21,{:0}{:0}{:1}{37}
26,{:19}{87}
27,{35}
31,{77}{12}{202}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM