Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

line by line subraction

Status
Not open for further replies.

rhnaeco

Technical User
Aug 11, 2005
45
I'm not sure whether this is a sed or awk solution:

i have a file like this :

12.4277 -12.9941
12.4277 -13.2078
12.4278 -13.3616
12.4278 -13.3616
.... .... ....

i would like to subract the values in $3 from each other, e.g.
-13.2078 - -12.9941 = column in new file
-13.3616 - -13.2078 = same column

so that my results look like:
-0.2137
-0.1538
0

this column i would like to sum
e.g -0.3675

any help would be greatly apprieciated

thanks
rhnaeco
 
A starting point:
awk 'NR>1{d=$2-s;t+=d;print d}{s=$2}END{print t}' /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
thank you, but is it possible to create the file of 'sums' as well, as there are other commands i need to carry out on these for a separate result.

sorry, i wasn't particularly clear

thanks
Rhnaeco
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top