views:

40

answers:

2

Hi 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 the rows . Could anybody help me out with this ?

A: 

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.

dash-tom-bang
+1  A: 

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

Matt Bridges
Thanks a lot ! Just what i wanted, matt
Sharat Chandra