Isso pode ser feito com Python como:
Código:
#!/usr/bin/python
import re
import sys
SPACES = re.compile('\s+')
data_by_lat_long = {}
with open(sys.argv[1]) as f:
# get and print header
line = next(f)
print(line.strip())
for line in f:
data = SPACES.split(line.strip())
data_by_lat_long.setdefault((data[0], data[1]), []).append(data[2:])
for lat_long, data in data_by_lat_long.items():
results = zip(*data)
if '-9.99' in results[0]:
results[0] = ('-9.99', )
avg = tuple(str(sum(float(x) for x in d) / len(d)) for d in results)
print('\t'.join(lat_long + avg))
Resultados:
Lat Long air_temp sst wind_speed wave_height wave_period
65.3 7.3 3.15 6.4 6.35 3.0 9.0
61.1 1 -9.99 8.8 8.7 3.5 7.0
61.6 1.3 -9.99 8.7 8.75 3.5 7.0
e
Lat Long air_temp sst wind_speed wave_height wave_period
0 -0.7 24.0 24.8 5.7 1.0 3.0
0 0.1 22.9 22.5 7.7 1.0 5.0
0 0.3 27.0 27.0 4.6 2.0 12.0
0 0.2 24.0 26.0 4.6 2.0 6.0
0 0.8 27.0 28.0 7.2 1.5 9.0
0 -0.3 27.0 27.5 5.7 1.5 8.0
0 0.5 24.6 25.0 10.3 2.0 6.0
0 -0.2 -9.99 30.4 3.6 1.5 8.0
0 0.4 23.0 23.0 8.2 1.5 3.0
0 0.7 -9.99 27.5 6.6 1.25 9.0
0 0 25.3916666667 25.9416666667 3.51666666667 1.66666666667 9.08333333333
0 0.6 26.7 27.0 5.1 1.5 10.0