The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Array values treated as one cytriesbash Shell Programming and Scripting 1 07-16-2008 08:46 PM
How to use array values after the loop. Devesh5683 Shell Programming and Scripting 1 05-13-2008 07:38 PM
incorrect array values jhillier UNIX for Dummies Questions & Answers 6 01-04-2008 04:44 AM
Assigning values to an array yongho UNIX for Dummies Questions & Answers 4 07-13-2005 08:49 PM
array values in a command eeisken Shell Programming and Scripting 3 06-22-2005 04:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-21-2008
shantanuo shantanuo is offline
Registered User
  
 

Join Date: Aug 2008
Location: Mumbai
Posts: 79
Compare array values

# tail myprocesses.txt
178 processes at Tue Oct 21 14:33:01 IST 2008
16 MySQL processes at Tue Oct 21 14:33:01 IST 2008
175 processes at Tue Oct 21 14:36:01 IST 2008
60 MySQL processes at Tue Oct 21 14:36:01 IST 2008
192 processes at Tue Oct 21 14:39:01 IST 2008
64 MySQL processes at Tue Oct 21 14:39:01 IST 2008
178 processes at Tue Oct 21 14:42:01 IST 2008
67 MySQL processes at Tue Oct 21 14:42:01 IST 2008
176 processes at Tue Oct 21 14:45:01 IST 2008
68 MySQL processes at Tue Oct 21 14:45:01 IST 2008

# tail myprocesses.txt | grep -i 'mysql processes' | awk '{print $1}'
16
60
64
67
68

I want to compare the above values and if all of them are more than 50 then echo "Problem". In the above mentioned case, it will not echo "Problem" because first value i.e. 16 is less than 50
  #2 (permalink)  
Old 10-21-2008
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
Try this:
Code:
grep -i 'mysql processes' | awk ' $1 > 50 {print $1, "Problem"}'
  #3 (permalink)  
Old 10-21-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,794
Code:
awk 'END { if (!f) print "Problem" }
/[Mm][Yy][Ss][Qq][Ll]/ && $1 < 50 { ++f; exit }
' myprocesses.txt

If you want to check only the last 10 lines:


Code:
tail ... | awk ...
Sponsored Links
Closed Thread

Bookmarks

Tags
array

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 08:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0