The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Looping and using Sed digobh Shell Programming and Scripting 4 02-04-2008 05:25 PM
looping search question alfredo123 Shell Programming and Scripting 3 11-16-2006 12:39 AM
Perl question - looping through an array of hashrefs kregh99 Shell Programming and Scripting 2 03-19-2004 07:48 AM
nested looping question Sn33R Shell Programming and Scripting 7 09-26-2003 11:14 AM
looping question hedrict UNIX for Dummies Questions & Answers 1 03-11-2002 01:19 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-23-2006
Registered User
 

Join Date: Feb 2006
Posts: 65
Unhappy Looping question

Hi,

I have series of data stored in a variable xyz:
(between 0 and 100)
example:
20 45 98 21.....

I need to find if there is/are any occurance of data > 95

Not sure what kind of looping is required to check.

Please help.
thanks
Reply With Quote
Forum Sponsor
  #2  
Old 02-23-2006
Registered User
 

Join Date: Feb 2006
Location: Schenectady, NY
Posts: 130
Using ksh and, if I'm reading your question correctly, xyz="20 45 98 21" simply
Code:
for N in $xyz
do
    if [ $N -gt 95 ]
    then
        echo "$N is greater than 95"
    fi
done
You can add an index if you need to know WHAT value(s) are greater than 95

Code:
I=0
for N in $xyz
do
    if [ $N -gt 95 ]
    then
        echo "$N is greater than 95 and is element $I"
    fi
    (( I = I + 1 ))
done
Reply With Quote
  #3  
Old 02-24-2006
Registered User
 

Join Date: Feb 2006
Posts: 65
Thank you Hegemaro.

It worked like a charm.

Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0