|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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 1i tried this but it is giving above error.. Last edited by Franklin52; 02-28-2013 at 09:41 AM.. Reason: Code tags |
|
#4
|
|||
|
|||
|
Use
/usr/xpg4/bin/awk or
nawk on Solaris.
|
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
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.txtLast edited by Franklin52; 02-28-2013 at 09:41 AM.. Reason: Please use code tags for data and code samples |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|