Bash 长到宽格式
在bash中,可能使用awk,我想将长格式的表转换为宽格式。为简单起见: 输入:Bash 长到宽格式,bash,parsing,variables,awk,format,Bash,Parsing,Variables,Awk,Format,在bash中,可能使用awk,我想将长格式的表转换为宽格式。为简单起见: 输入: A one A two A three B seven B eight B nine 输出: A one,two,three B seven,eight,nine 一种方法,使用: 不需要排序输入欢迎使用堆栈溢出。这也是一个面向专业和热心程序员的问答网站。目标是在问题中添加一些自己的代码,以显示您自己为解决此问题所做的研究工作。请参阅: $ datamash -W -g1 collapse 2 < inp
A one
A two
A three
B seven
B eight
B nine
输出:
A one,two,three
B seven,eight,nine
一种方法,使用:
不需要排序输入欢迎使用堆栈溢出。这也是一个面向专业和热心程序员的问答网站。目标是在问题中添加一些自己的代码,以显示您自己为解决此问题所做的研究工作。请参阅:
$ datamash -W -g1 collapse 2 < input.txt
A one,two,three
B seven,eight,nine
$ perl -lane 'push @{$groups{$F[0]}}, $F[1];
END { $" = ",";
for $g (sort keys %groups) { print "$g\t@{$groups{$g}}" }}' input.txt
A one,two,three
B seven,eight,nine