I have a gridded data file in column format as:
ifile.txt
x y value
20.5 20.5 -4.1
21.5 20.5 -6.2
22.5 20.5 0.0
20.5 21.5 1.2
21.5 21.5 4.3
Perl solution:
#!/usr/bin/perl -an
$h{ $F[0] }{ $F[1] } = $F[2] unless 1 == $.;
END {
@s = sort { $a <=> $b } keys %h;
print ' ' x 5;
printf '%5.1f' x @s, @s;
print "\n";
for my $u (@s) {
print "$u ";
printf '%5.1f', $h{$u}{$_} for @s;
print "\n";
}
}
-n
reads the input line by line-a
splits each line on whitespace into the @F array