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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparison of values in back-to-back lines 1

Status
Not open for further replies.

tini1208

Technical User
Feb 13, 2006
56
DE
hi,

i have following problem.
my file looks like this (it's only a part, most of the files have several tausend rows):

19.996091 -85.413194 2686.192
19.979215 -85.413961 2686.585
19.962339 -85.414726 2686.863
19.945468 -85.415490 2686.914
19.928617 -85.416251 2687.114
19.911784 -85.417010 2687.420
19.894956 -85.417768 2687.510
19.878128 -85.418525 2687.818
19.861288 -85.419283 2688.010
19.844434 -85.420041 2688.228
19.827575 -85.420800 2688.420

i want to determine the difference of the values of column 3 of back-to-back lines, thus 2686.192 - 2686.585 = x and 2686.585 - 2686.863 = y and so on.
when x or y are smaller than, let me say, 500, print the row in a output file. i think, the printing is no problem, but the determination of the differences.

i anyboby out there, who can help me?

thanks a lot!
tini
 
And what have you tried so far ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
i looked up in several books and tried to find an approach in the internet, but i can't find anything, which helps me (mostly, i didn't understand, what they want to say). but i think, i have to use for and next, but i don't know, if it is the right way?
 
A starting point:
awk 'NR>1{d=$3-f3;if(d<500)print $0,d}{f3=$3}' /path/to/input > output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
thanks a lot...this works well!
cheers, tini
 

tini1208,

Why not click on that "Thank PHV for this valuable post!" link at the bottom of PHV's helpful post?

 
sorry, i didn't know...but i did it now!
cheers, tini
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top