Find the numeric value in a string and then check the max. value | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Find the numeric value in a string and then check the max. value

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-28-2013
lovelysethii lovelysethii is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 10 October 2014, 5:30 AM EDT
Posts: 89
Thanks: 6
Thanked 0 Times in 0 Posts
Find the numeric value in a string and then check the max. value

hi,

i have a string
"[10/2/08 6:19:55:834 EDT] 00000069 ThreadMonitor W WSVR0606W: Thread "WebContainer : 43|null" (00000069) was previously rep
orted to be hung but has completed. It was active for approximately 47533430 milliseconds. There is/are 43 thread(s) in tot
al in the server that still may be hung."

and i want to find "There is/are 43", i am using the following command for this:

Code:
grep 'There is/are' hung.txt | cut -c219-234

there may have multiple values for the above string, so i need to check the max number out of this string. my initial approach is:

Code:
grep 'There is/are' hung.txt | cut -c230-234 | tr -dc '[0-9]'


i am only cutting the numeric values but all the values are printing into a single line. plz help me with this or if there is another way to do this????

thanks in advance

Last edited by Franklin52; 02-28-2013 at 09:41 AM.. Reason: Please use code tags for data and code samples
Sponsored Links
    #2  
Old 02-28-2013
pamu pamu is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 15 September 2014, 8:06 AM EDT
Posts: 1,649
Thanks: 58
Thanked 478 Times in 474 Posts
Try sth like this...


Code:
awk -F "is/are" '{split($2,P," ");a=a>P[1]?a:P[1]}END{print a}' file

Sponsored Links
    #3  
Old 02-28-2013
lovelysethii lovelysethii is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 10 October 2014, 5:30 AM EDT
Posts: 89
Thanks: 6
Thanked 0 Times in 0 Posts

Code:
bash-3.2$ awk -F "is/are" '{split($2,P," ");a=a>P[1]?a:P[1]}END{print a}' hung.txt
awk: syntax error near line 1
awk: bailing out near line 1


i tried this but it is giving above error..

Last edited by Franklin52; 02-28-2013 at 09:41 AM.. Reason: Code tags
    #4  
Old 02-28-2013
pamu pamu is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 15 September 2014, 8:06 AM EDT
Posts: 1,649
Thanks: 58
Thanked 478 Times in 474 Posts
Use /usr/xpg4/bin/awk or nawk on Solaris.
Sponsored Links
    #5  
Old 02-28-2013
lovelysethii lovelysethii is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 10 October 2014, 5:30 AM EDT
Posts: 89
Thanks: 6
Thanked 0 Times in 0 Posts
here is what i did for the above issue:

Code:
grep 'There is/are' hung.txt | cut -c231-233 | grep '[0-9]'|sed 's/^[ \t]*//;s/[ \t]*$//'>max.txt

first i tried to cut the numberic part of a string value and then store it into the text file and then to get the max value i tried following command and its working now..

Code:
awk '$0>x{x=$0};END{print x}' max.txt


Last edited by Franklin52; 02-28-2013 at 09:41 AM.. Reason: Please use code tags for data and code samples
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
check if a string is numeric megha2525 Shell Programming and Scripting 14 11-14-2011 09:09 AM
How to check for a Numeric Value? chagan02 Shell Programming and Scripting 2 05-04-2011 04:16 PM
Find and Replace random numeric value with non-numeric value Bahf1s UNIX for Dummies Questions & Answers 6 08-19-2010 10:53 AM
Need to find a string, check the next line, and if it matches certain criteria, replace it with a s midniteslice Shell Programming and Scripting 6 11-16-2009 02:08 PM
check the given string is numeric or not. knowledge_gain Programming 11 02-03-2009 10:25 AM



All times are GMT -4. The time now is 05:28 AM.