我尝试在 awk 中创建一个伪多维数组。
# Calculate cumulative context score
BEGIN { FS=OFS="\t" }
{
a[$2+FS+$7,$3]+=$6
}
END { for (i,j) in a
{ print i,j,a[i,j] }
}
输出:
awk: ccstscan.awk:9: END { for (i,j) in a
awk: ccstscan.awk:9: ^ syntax error
这就是 GNU awk 手册中提到的内容:
要测试特定索引序列是否存在于多维数组中,请使用与单维数组相同的运算符 (in)。将整个索引序列写在括号中,用逗号分隔,作为左操作数:
(subscript1, subscript2, ...) in array
我尝试修改脚本以创建一个真正的多维数组:
BEGIN { FS=OFS="\t" }
{
a[$2+FS+$7][$3]+=$6
}
END { for i in a
{
for j in a[i]
{ print i,j,a[i][j]
}
}
}
我用 gawk 运行它。它也给出了一个错误:
gawk: ccstscan.awk:6: a[$2+FS+$7][$3]+=$6
gawk: ccstscan.awk:6: ^ syntax error
gawk: ccstscan.awk:9: END { for i in a
gawk: ccstscan.awk:9: ^ syntax error
gawk: ccstscan.awk:11: for j in a[i]
gawk: ccstscan.awk:11: ^ syntax error
gawk: ccstscan.awk:11: for j in a[i]
gawk: ccstscan.awk:11: ^ syntax error
gawk: ccstscan.awk:12: { print i,j,a[i][j]
gawk: ccstscan.awk:12: ^ syntax error
制作和扫描多维关联数组的正确格式是什么