0

I have a file, file1, with following values

50
43
43
39
38

I have defined a constant parameter "framei=218" and I want to obtain the following output, file2

218   50
218.5 43
219   43
219.5 39
220   38

will be something like the following

awk '{print NR*'$framei' " " $s}' file1 > file2

3 Answers 3

1

The formula needs to be a bit more complex:

awk '{print (NR-1)/2+'$framei' " " $s}'

Or, if you initialize $framei to 217.5:

awk '{print NR/2+'$framei' " " $s}'
0
awk '{print '$framei'+NR/2-0.5 " " $s}' file1 > file2
0

Done by Below command

awk 'BEGIN{sum=218}NR>1{sum=sum+0.5}{print sum,$1}' file

output

218 50
218.5 43
219 43
219.5 39
220 38

Python

#!/usr/bin/python
sum=218
k=open('file','r')
l=k.readlines()
print len(l)
for i in range(0,len(l),1):
    print sum,l[i].strip()
    sum=sum+0.5

output

218 50
218.5 43
219 43
219.5 39
220 38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .