I have a data file with two columns,
for the second column I want to find the minimum,
and subtract this minimum from each value in the second column,
how to realize this using C shell
For example, I have
1 -2.4
2 -4.8
3 7.9
I wanna output
1 2.4
2 0
3 12.7
Thanks!
my $min=0;
while(<DATA>){
chomp;
my @tmp = split;
$hash{$.}->{val}=[@tmp];
$min=($tmp[1]<=$min)?$tmp[1]:$min;
}
foreach my $key (sort {$a<=>$b} keys %hash){
print $hash{$key}->{val}->[0]," ",$hash{$key}->{val}->[1]-$min,"\n";
}
__DATA__
1 -2.4
2 -4.8
3 7.9
Thanks a lot, summer cherry!
Anyone can help on a C shell version?
Appreciate your time!
Abid
February 23, 2011, 1:44pm
4
data
1 -2.4
2 -4.8
3 7.9
set asd = `awk '$2< min {min=$2;} END{ print min}' data`
awk '{$2=$2 - '"$asd"'} {print $0}' data