How to find whenther given value is in betwwen min and Max in unix shell scripting


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to find whenther given value is in betwwen min and Max in unix shell scripting
# 1  
Old 07-26-2007
How to find whenther given value is in betwwen min and Max in unix shell scripting

Hi

I wanted to write a shell script with an if condition

Example
MinValue=10
MaxValue=30
logvalue = some integer value that script reads from the command line arguement
I wanted to check whether log value greater than or equal to10 and less than equal to 30
and proceed with the rest of hte code only if logValue is between or equal to the MinValue and MaxVlaue

If condition should work like this in unix shell scripting

if(MinValue<=logValue<=MaxValue)
Thanks in advance for all the help
# 2  
Old 07-26-2007
Code:
#!/bin/ksh
typeset -i MinValue=10
typeset -i MaxValue=30
typeset -i LogValue
echo 'Enter log value:'
read LogValue
if [ ${LogValue} -ge ${MinValue} -a ${LogValue} -le ${MaxValue} ]; then
  echo 'Found in between'
fi

# 3  
Old 07-27-2007
Code:
echo 20  | awk '{ if ( 20 <= $0 && $0 <= 30 ) { print "in-between" } else { print "out-of-range" } }'


Last edited by matrixmadhan; 07-27-2007 at 02:25 AM.. Reason: range specification
# 4  
Old 07-27-2007
Thanks for the solution
It worked
I am just wondering whether the ; at the end of if (if [ ];then ) is necessary or notthe reason why I was asking is it worked with out ; and with ; so just wondering is there anything that I am missing if I don't keep the ; at the end of if

Is there any difference between

if [ ];then

fi
and

if [ ]
then

fi



Thanks in advance
Pinky
# 5  
Old 07-27-2007
The simicolon ';' is used in korn shell as a command separator.

The reason for having '; then' is to save space and have fewer lines in the shell.
# 6  
Old 07-27-2007
Thanks
That's really useful info I appreciate it

Pinky
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find min and max time taken from a log file

You have a log file as attached in sample input with various operations and time taken by each of them. Write a script to find the min and max time taken for each operation. Sample output is attached. Sample Input is given as below: operation1,83621 operation2,72321 operation3,13288... (1 Reply)
Discussion started by: Chandan_Bose
1 Replies

2. Shell Programming and Scripting

Get min and max value in column

Gents, I have a big file file like this. 5100010002 5100010004 5100010006 5100010008 5100010010 5100010012 5102010002 5102010004 5102010006 5102010008 5102010010 5102010012 The file is sorted and I would like to find the min and max value, taking in the consideration key1... (3 Replies)
Discussion started by: jiam912
3 Replies

3. Shell Programming and Scripting

awk script to find min and max value

I need to find the max/min of columns 1 and 2 of a 2 column file what contains the special character ">". I know that this will find the max value of column 1. awk 'BEGIN {max = 0} {if ($1>max) max=$1} END {print max}' input.file But what if I needed to ignore special characters in the... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

4. Shell Programming and Scripting

to find min and max value for each column!

Hello Experts, I have got a txt files which has multiple columns, I want to get the max, min and diff (max-min) for each column in the same txt file. Example: cat file.txt a 1 4 b 2 5 c 3 6 I want ouput like: cat file.txt a 1 4 b 2 5 c 3 6 Max 3 6 Min 1 4 Diff 2 2 awk 'min=="" ||... (4 Replies)
Discussion started by: dixits
4 Replies

5. Shell Programming and Scripting

How to find the average,min,max ,total count?

Hi , Below is my sample data,I have this 8 column(A,B,C,D,E,F,G,H) in csv file. A , B ,C ,D ,E ,F,G ,H 4141,127337,24,15,20,69,72.0,-3 4141,128864,24,15,20,65,66.0,-1 4141,910053,24,15,4,4,5.0,-1 4141,910383,24,15,22,3,4.0,-1 4141,496969,24,15,14,6,-24.0,-18... (7 Replies)
Discussion started by: vinothsekark
7 Replies

6. Shell Programming and Scripting

Find min.max value if matching columns found using AWK

Input_ File : 2 3 4 5 1 1 0 1 2 1 -1 1 2 1 3 1 3 1 4 1 6 5 6 6 6 6 6 7 6 7 6 8 5 8 6 7 Desired output : 2 3 4 5 -1 1 4 1 6 5 6 8 5 8 6 7 (3 Replies)
Discussion started by: vasanth.vadalur
3 Replies

7. Shell Programming and Scripting

get min, max and average value

hi! i have a file like the attachement. I'd like to get for each line the min, max and average values. (there is 255 values for each line) how can i get that ? i try this, is it right? BEGIN {FS = ","; OFS = ";";max=0;min=0;moy=0;total=0;freq=890} $0 !~ /Trace1:/ { ... (1 Reply)
Discussion started by: riderman
1 Replies

8. Shell Programming and Scripting

how to find min, max dates in a file

hello friends...:-) i need some help i have a file cantain like this Star1 ,NetWork,09/02/2008 Star1 ,NetWork,10/02/2008 Star1 ,NetWork,11/02/2008 Star2 ,NetWork,08/03/2008 Star2 ,NetWork,09/04/2008 Star2 ,NetWork,10/05/2008 i need to find out min, max dates the output look like... (6 Replies)
Discussion started by: gemini106
6 Replies

9. AIX

Unix shell scripting to find latest file having timestamp embedded...

Hi guys, I have a directory in UNIX having files with the below format, i need to pickup the latest file having recent timestamp embedded on it, then need to rename it to a standard file name. Below is the file format: filename_yyyymmdd.csv, i need to pick the latest and move it with the... (2 Replies)
Discussion started by: kaushik25
2 Replies

10. Shell Programming and Scripting

min and max value of process id

We are running a AIX 5.2 OS. Would anyone happen to know what the max value for a process id could be? Thanks jerardfjay :) (0 Replies)
Discussion started by: jerardfjay
0 Replies
Login or Register to Ask a Question