Reputation: 11
I have a file containing one column of number:
1
2
4
7
10
12
and i want output like below
1
3
2
e.g I need difference of each two iteration.
like 2-1=1
, 7-4=3
, 12-10=2
Upvotes: 0
Views: 54
Reputation: 5298
awk 'NR%2{x=$0;next}{print $0-x}' File
For the odd lines, save the line (number) to variable x
. For even lines, print the difference using previously saved x
Upvotes: 1