Sponsored Content
Top Forums Shell Programming and Scripting Need help with the logic for ksh script Post 303001444 by Don Cragun on Thursday 3rd of August 2017 03:39:08 PM
Old 08-03-2017
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:
Mod Comment 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.
 

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

2. Shell Programming and Scripting

Need help with the logic for ksh script

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... (1 Reply)
Discussion started by: desant
1 Replies
ARITHMETIC(6)							 BSD Games Manual						     ARITHMETIC(6)

NAME
arithmetic -- quiz on simple arithmetic SYNOPSIS
arithmetic [-o +-x/] [-r range] DESCRIPTION
arithmetic asks you to solve problems in simple arithmetic. Each question must be answered correctly before going on to the next. After every 20 problems, it prints the score so far and the time taken. You can quit at any time by typing the interrupt or end-of-file character. The options are as follows: -o By default, arithmetic asks questions on addition of numbers from 0 to 10, and corresponding subtraction. By supplying one or more of the characters +-x/, you can ask for problems in addition, subtraction, multiplication, and division, respectively. If you give one of these characters more than once, that kind of problem will be asked correspondingly more often. -r If a range is supplied, arithmetic selects the numbers in its problems in the following way. For addition and multiplication, the numbers to be added or multiplied are between 0 and range, inclusive. For subtraction and division, both the required result and the number to divide by or subtract will be between 0 and range. (Of course, arithmetic will not ask you to divide by 0.) The default range is 10. When you get a problem wrong, arithmetic will remember the numbers involved, and will tend to select those numbers more often than others, in problems of the same sort. Eventually it will forgive and forget. arithmetic cannot be persuaded to tell you the right answer. You must work it out for yourself. DIAGNOSTICS
``What?'' if you get a question wrong. ``Right!'' if you get it right. ``Please type a number.'' if arithmetic doesn't understand what you typed. SEE ALSO
bc(1), dc(1) BSD
May 31, 1993 BSD
All times are GMT -4. The time now is 08:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy