#!/usr/bin/perl use strict; if (@ARGV < 1) { die < .. The equations can refer to $1,$2.. which are the columns in the input files. $0 refers to the line number. If equation not specified '$0:$1:$2' is assumed, i.e. output the average of column 1 and 2, using the line number as the key. The key should evaluate to a integer. Alternatively functions avg(eq) and dev(eq) can be used to plot the average of the equation (default behaviour) but also the std. deviation. e.g. '$0:avg($1):dev($1)' outputs the average and the std. deviation of column 1. EOL } my $eqs; if ($ARGV[0] =~ /:/) { $eqs=shift @ARGV; } else { $eqs='$1:$1:$2'; #default output } my @files=<@ARGV>; die "No files found" if (scalar(@files)==0); my @eqns=split /:/,$eqs; my @proc; my $cols=scalar(@eqns); print "\#key:\n"; print "\#$eqns[0]\n\#\n"; print "\#column equations:\n"; for (my $i=1;$i) #load { s/^\s+//; #remove leading whitespace s/\s+^//; #remove trailing whitespace if (/^\#/) {print $_; } #header line elsif (/^$/) { } #empty line else { $line++; #data line split /\s+/; #break on space unshift @_,$line; #add as first column my $x=evalfunc($eqns[0],@_); for (my $i=1;$i<$cols;$i++) { push @{%{$data[$i-1]}->{$x}},evalfunc($eqns[$i],@_); } } } close FI; } #print the result: my @t; #tmp foreach (sort{$a<=>$b} keys %{$data[0]}) { # print $_."\t"; #average of first column # print avg(@{%{$data[0]}->{$_}})."\t"; for (my $i=1;$i<$cols;$i++) { @t=@{%{$data[$i-1]}->{$_}}; if ($proc[$i] eq "avg") { print avg(@t)."\t"; } elsif ($proc[$i] eq "dev") { print dev(@t)."\t\t"; } } print "\n"; }