|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi all, I have a file which looks like: Code:
0 1.1985506 1 1.2237930 2 1.2159038 3 1.2668828 4 1.2650216 5 1.2474344 6 1.2817688 7 1.2721698 8 1.2665005 9 1.2826315 10 1.2797879 11 1.3201736 12 1.3116595 13 1.3361583 14 1.3309238 15 1.3521332 16 1.3593159 17 1.3558449 18 1.3792990 19 1.3990164 20 1.4039725 21 1.4026414 22 1.4141786 23 1.4655373 24 1.4627539 25 1.4684621 26 1.4994614 27 1.4573526 28 1.4736820 29 1.4868084 30 1.4942920 and i need to get the closest values that result from successive increments in second column (say for example 0.2) starting from the first value until the end of the file is reached, so my output would be in this case: Code:
0 1.1985506 19 1.3990164 Note that the value resulting from the addition of the last matched value (1.3990164) and the increment (0.2), i.e. 1.5990164, is greater than the last value of the file (1.4942920), so that's why 1.3990164 is the last printed value. Is this possible to do? I would appreciate an awk, perl or python suggestion, since those are the programing languages I use at work. |
| Sponsored Links | |
|
|
|
#2
|
|||
|
|||
|
Code:
#! /bin/sh
awk '
BEGIN {
delta=0.2
# process first line
getline
value=$2
print
}
{
if ( $2-value > delta ) {
print
value=$2
}
}' input |
| The Following User Says Thank You to chihung For This Useful Post: | ||
ezitoc (02-09-2012) | ||
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
Nice! Thank you!
|
| Sponsored Links | ||
|
|
![]() |
| Tags |
| awk, closest, increment, nearest, successive |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| stunnell log file has reached its limit | beckyboo | UNIX for Dummies Questions & Answers | 13 | 09-12-2011 11:58 AM |
| Find a repeated number in a particular field and dont increment value of variable | SBC | Shell Programming and Scripting | 2 | 08-16-2009 12:47 AM |
| sed match closest/nearest pattern | sudheer1984 | UNIX for Advanced & Expert Users | 1 | 07-02-2009 03:59 AM |
| cpio: Ulimit reached for file output | dustytina | SCO | 0 | 10-25-2007 08:19 PM |
| tar: 0511-194 Reached end-of-file before expected. | Funky_ass | Shell Programming and Scripting | 4 | 08-07-2006 07:58 AM |
|
|