假设我有以下数据:
# all the numbers are their own number. I want to reshape exactly as below
0 a
1 b
2 c
0 d
1 e
2 f
0 g
1 h
2 i
...
而且我想重塑数据,使其是:
0 a d g ...
1 b e h ...
2 c f i ...
无需编写复杂的作品。使用unix / bash工具包可以做到这一点吗?
是的,我可以用一种语言来做到这一点。这个想法是NOT TO“只是”做到这一点。因此,如果存在某种cat X.csv | rs [magic options]
解决方案(并且rs
或bash reshape命令会很棒,除非它在debian Stretch上不起作用),这就是我想要的。
否则,包含命令或脚本组成的等效答案不在范围内:已经知道了,但宁愿没有。
datamash
:$ datamash -s -W -g 1 collapse 2 < file
0 a,d,g
1 b,e,h
2 c,f,i
选项:
-s
排序-W
使用空格(空格或制表符)作为分隔符g 1
组]collapse 2
打印逗号分隔的第二个字段的值列表tr
:$ datamash -s -W -g 1 collapse 2 < file | tr '\t,' ' '
0 a d g
1 b e h
2 c f i