input
-200 2.4
0 2.6
30 2.8
output
-500 0
-499 0
-488 0
..........
..........
....
-200 2.4
....
...
0 2.6
...
...
30 2.8
...
......
.......
499 0
500 0
input
-200 2.4
0 2.6
30 2.8
output
-500 0
-499 0
-488 0
..........
..........
....
-200 2.4
....
...
0 2.6
...
...
30 2.8
...
......
.......
499 0
500 0
#!/usr/bin/env ruby -w
# 1.9.1
h={}
File.foreach("file"){|x|a,b=x.split;h[a.to_i]=b}
(-500..500).to_a.each{|i|print (h.key?(i))?"#{i} #{h}\n":"#{i} 0\n"}
$ ruby myscript.rb
If you want to use Python:
#!/usr/bin/python
import sys
fname=sys.argv[1]
kd={}
for line in open(fname):
k,v = line.split()
kd[k] = v
for i in range(-500,501):
if str(i) in kd:
print '%s %s' % (i,kd[str(i)])
else:
print '%s 0' % i
Usage:
script.py input:file
the output is not so clear, do you need fill the data as 0 or the value such as:
200 2.4
199 2.4
...
0 2.6
1 2.6
or
200 2.4
199 0
...
0 2.6
1 0
OP asked for awk script
awk -v s=-500 -v e=500 '
{
while ( $1 > s ) print s++"\t0";
print $1"\t"$2;
s=$1+1;
}
END {
while (s<=e) print s++"\t0";
} ' input
Another awk:
awk '{a[$1]=$2}END{for (i=-500;i<=500;i++){print i,"\t",a==""?"0":a}}' input_file
Thanx alot guys!!!