Awk 按列进行数据分区
我有一个50行1.5M列的大矩阵。从这150万列中,前两列是我的标题 我试图将数据按列分割成小块。例如,每个小集合将有50行和100列。但是每个小数据都必须有上面提到的前两列作为标题 我试过了Awk 按列进行数据分区,awk,cut,data-partitioning,Awk,Cut,Data Partitioning,我有一个50行1.5M列的大矩阵。从这150万列中,前两列是我的标题 我试图将数据按列分割成小块。例如,每个小集合将有50行和100列。但是每个小数据都必须有上面提到的前两列作为标题 我试过了 awk '{print $1"\t"$2"\t"}' test | cut -f 3-10 awk '{print $1"\t"$2"\t"}' test | cut -f 11-20 ... 或 但上述措施都不起作用 有没有一种有效的方法可以做到这一点呢?只有一种方法。我不知道它(awk)是否能处理如
awk '{print $1"\t"$2"\t"}' test | cut -f 3-10
awk '{print $1"\t"$2"\t"}' test | cut -f 11-20
...
或
但上述措施都不起作用
有没有一种有效的方法可以做到这一点呢?只有一种方法。我不知道它(awk
)是否能处理如此多的列,但请尝试一下。它使用模运算符将每条线切割为特定数量的列
awk '{
## Print header of first line.
printf "%s%s%s%s", $1, FS, $2, FS
## Count number of columns printed, from 0 to 100.
count = 0
## Traverse every columns but the first two keys.
for ( i = 3; i <= NF; i++ ) {
## Print header again when counted 100 columns.
if ( count != 0 && count % 100 == 0 ) {
printf "%s%s%s%s%s", ORS, $1, FS, $2, FS
}
## Print current column and count it.
printf "%s%s", $i, FS
++count
}
## Separator between splits.
print ORS
}
' infile
结果是:
key1 key2 one two three four
key1 key2 five six seven eight
key1 key2 nine ten
key1 key2 one2 two2 three2 four2
key1 key2 five2 six2 seven2 eight2
key1 key2 nine2 ten2
什么样的软件在它正常的头脑中会输出150万列(你是说百万的M?还是1000的罗马数字的M?)(无论哪种方式都是疯狂的,只是数量级不同;-)。你不能让数据以另一种方式传递,50列,150万行吗?祝你好运
key1 key2 one two three four five six seven eight nine ten
key1 key2 one2 two2 three2 four2 five2 six2 seven2 eight2 nine2 ten2
key1 key2 one two three four
key1 key2 five six seven eight
key1 key2 nine ten
key1 key2 one2 two2 three2 four2
key1 key2 five2 six2 seven2 eight2
key1 key2 nine2 ten2