Quote:
Originally Posted by
desant
Hi guys
I am having hard time to figure out the logic for the following problem:
I have a line of sorted numbers , for example
19 34 44 49 64
I am trying to find the way to determine which two numbers are in between the number I have specified.
for example if
34 is specified 19 and 44 should be returned.
Thanks a lot for any help and ideas
Moderator's Comments:
|
|
Please use CODE tags as required by forum rules!
|
|
This is very vague! In addition to the question of whether the line is in a variable or in a file, there is also the question "How is the number you have specified found?". Is it a command line parameter? Is it a constant? Is it a variable?
And, is the number you specify always a value that is in the line? The code RudiC suggested assumes that it will be. (And, since that was true in your example, that is a reasonable assumption.) But the logic will need to be different if that assumption is not always valid.
As always, it also helps us avoid wasting time making suggestions that won't work if you tell us what operating system (including version number) and shell (including version number) you're using. The
grep -C option is a non-standard feature that is available on some operating systems, but not all. The
$'\n' expansion is recognized by 1993 and later versions of the Korn shell, but not by the 1988 and earlier versions.