Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 长到宽格式_Bash_Parsing_Variables_Awk_Format - Fatal编程技术网

Bash 长到宽格式

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

在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 < 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