私はawkで擬似多次元配列を作成しようとしました。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のマニュアルに記載されているものです。
:To test whether a particular index sequence exists in a multidimensional array, use the same operator (in) that is used for single dimensional arrays. Write the whole sequence of indices in parentheses, separated by commas, as the left operand:
(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
多次元連想配列を作成し、スキャンし、正しいフォーマットするものです
ループはありません(と)、それはfor i in aであり、for i in aではありません。また、古いgawkを使用しているため、おそらく配列インデックスについての最初の構文エラーが発生します。真の多次元配列はかなり最近追加されたものです。 –
私はgawk4の配列の配列のリンクを追加します。http://www.gnu.org/software/gawk/manual/html_node/Arrays-of-Arrays.html – Kent