Dears,
I have a list as follows,
2
4
8
If I want to find the difference between two consecutive rows. Then I have to store the specific rows in two variables and then find the difference. Could someone tell how this can be done.
Regards,
Dears,
I have a list as follows,
2
4
8
If I want to find the difference between two consecutive rows. Then I have to store the specific rows in two variables and then find the difference. Could someone tell how this can be done.
Regards,
You can use this poor script:
#!/bin/sh
x="1"
if [ $1 != "" ]; then
a=`sed -n '$x,$xp' $1`
x=$(($x+1))
b=`sed -n '$x,$xp' $1`
fi
if [ $a = $b ];then
echo "ok"
else
echo "no"
fi
However this scrip is just a stupid! You can write something similar with "while" and better.
Converting absolute to relative and vice versa is a very common requirement.
There really should be a standard tool for it, hmm....
Anyway here's a python script I use:
#!/usr/bin/env python
import sys
prev=0
while 1:
line = sys.stdin.readline()
if line == '':
break
try:
cur = float(line)
print cur - prev
prev = cur
except:
pass
nawk '{print $0-prev; prev=$0}' listFile
NOTE: pixelbeat, I think you've replied to the wrong thread.
No I didn't. I was just speaking in more general terms.
vgersh99, is right
2
4
2
2-4=-2
4-2=2
'difference' != absolute
vgersh99 your method is correct.
Regards