Here's a quick Perl script which should do the job for you:
#!/usr/bin/perl
use strict;
my %result;
my @data;
my %data;
my @degrees;
my $infile = shift() || die "Usage: $0 <file>\n";
# Read source data from input file
open IN, '<', $infile
or die "Couldn't open data file: $!\n";
while (my $line = <IN>) { chomp $line; push @data, $line; };
close IN;
# Convert data lines to hash
foreach my $line (@data) {
my ($count, $degree) = split(/\s+/, $line);
$data{$degree}++;
};
# Get sorted degrees for count-up iteration
@degrees = sort { $a <=> $b } keys %data;
# Iterate degrees, adding each one's system count to result for this degree
# and all higher degrees
for (my $i = 0; $i < scalar(@degrees); $i++) {
my $degree = $degrees[$i];
my $count = $data{$degree};
for (my $j = $i; $j < scalar(@degrees); $j++) {
$result{$degrees[$j]} += $count;
};
};
# Output result counts
foreach my $degree (sort { $a <=> $b } keys %result) {
print "$result{$degree} $degree\n";
};
This script will require considerable memory for large input datasets; it slurps the entire input file before operating on it, because it doesn't look like the input file is sorted, and it's necessary to sort the data by degree before operating on it. That said, it should do the job for you pretty well -- let me know if it doesn't!
Can you define the transformation you want to apply to the data? Looking at the example, I can't tell what you're trying to do. – Aaron Miller – 2012-12-20T15:38:16.037
ok well,we have 3 AS(autonomous systems) that have degree of 0,and then we have 5 AS that they degree is 1 or less than 1 and so an – Arash – 2012-12-20T15:41:26.540
this is example of Cumulative distribution function (CDF) – Arash – 2012-12-20T15:43:04.577
1So it sounds like column 2 in the data is the degree, and what you're looking for is a result with the degree in column 2 and the number of systems of that degree (or less) in column 1. See answer below -- – Aaron Miller – 2012-12-20T15:46:57.500
i want this:we have 3 AS(autonomous systems) that have degree of 0,and then we have 5 AS that they degree is 1 or less than 1 and we have 6 AS that they Degree is 4 or less than 4 and ... – Arash – 2012-12-20T15:49:27.027
yep you right ;) – Arash – 2012-12-20T15:55:32.473