Maria
Maria

Reputation: 63

Difference between lines - awk - linux script

I need some help for one script that I am trying to write. I have one two column array the first column is years and the second values. I want to calculate the difference of the years and when the difference is less than 10, then I want to erase the line of the year that is close to the previous one (in this example the line that contains 1987). I thought that there is a way with awk, but I do not know... i tried some things but they do not work... Thanks just for reading this post, Maria

1980  0.5
1987  0.6
2020  0.2
2048  0.6

Upvotes: 1

Views: 418

Answers (1)

Tim Zimmermann
Tim Zimmermann

Reputation: 6420

awk '$1-prev >= 10 {print; prev=$1}' years.txt

This will check if the difference from the first field of the current line is at least 10, and print the line in that case.

Upvotes: 4

Related Questions