开发者

How to subtract data in different rows

I have a file that has a single column of numbers. I have to subtract value in row1 from value in row2, row3-row2; row4-row3 , row5-row4 and so on for all t开发者_开发问答he rows . Could anybody help me out with this ?


Here's a simple BASH script

FILENAME=$1

while read line
do
  if [ -n "$prevLine" ]
  then
    curLine=$line
    echo $(($curLine - $prevLine))
  fi
  prevLine=$line
done < $FILENAME

So you would type that into a file called rowdiff.sh or something like that. Then you chmod u+x rowdiff.sh to make it executable, then ./rowdiff.sh file_with_numbers.txt


Load the file up into OpenOffice Calc (or Excel, if you must), and assuming your data starts in A1, into cell B2 put =(B1-A1) and then copy&paste that all of the way down to the bottom of your dataset.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜