This looks like a job for awk
to me. awk
can be called from within gnuplot
like this:
sp '<awk ''{a[$1,$2]+=$3}END{for(i in a){split(i,s,SUBSEP);print s[2],s[1],a[i]}}'' test.data' w image
The awk script accumulates the value of the third column into the array a
. The key for each value is the string [$1 SUBSEP $2]
(equivalent to [$1,$2]
). $N
is the value of column N
. SUBSEP
is a built in variable whose value we don't need to worry about, we just refer to it again later.
When the whole file has been read (the END
block), split
is used to recover the first two columns by breaking up the array keys. The two parts of the key are printed, followed by the accumulated value. I rearranged the column order in awk as well (print s[2],s[1],a[i]
) so that back in gnuplot, using 2:1:3
is no longer needed.