looks like awk gets confused when there's a % next to a number.
command im running:
contents of /tmp/test.log
it looks like the awk is thinking 9% means 90%. which is not the case. how can i modify this awk command to accurate grab the right lines from the log?
---------- Post updated at 11:06 PM ---------- Previous update was at 10:18 PM ----------
If you do not mind, allow me to mention a few things about your snipet. -F" " : The default is already white space, making this unnecessary, unless you want to exclude tabs which in this case it not relevant. /phxnaz001b/ : Since this is the first field $1=="phxnaz001b" can be used instead to directly compare for the string, avoiding the regex lookup match, which is more expensive. /vol/ : this will try to match in the whole record or $0, which is more expensive than pointing directly to the field number i.e.$2 ~ /\/^vol/, also by using the anchor ^, it doesn't have to search the whole field nor will it match in the middle if found. && NF : Not necessary, it will always be true if any of the other expressions evaluate to true. print ; print: Not clear why you are displaying the same line twice if the range is between 80 and 82 inclusive. "%d:OK : Always 0 since you are not keeping tally of what falls outside the warning or critical level.
Changing those elements, the result would be something like:
or removing the individual prints:
Last edited by Aia; 12-13-2015 at 06:38 PM..
Reason: Explicit at id est
Here you convert $NF which is a percentage (string) to a number by extracting the number from it. substr function still gives you a string. To convert it to a decimal you add 0 to it.
Here you convert $NF which is a percentage (string) to a number by extracting the number from it. substr function still gives you a string. To convert it to a decimal you add 0 to it.
Adding a number to a string causes awk to use the characters at the start of that string that specify a numeric value (or zero if there isn't a leading number) to the number. Using substr() to strip off trailing non-digits isn't necessary.
produces something like:
(The string used to represent infinity in awk output varies from system to system (usually inf, infinity, Inf, or Infinity), but any input string starting with a case-insensitive inf should be interpreted by awk to be an infinite value when it is being evaluated as a number. And, as shown by the string starting with 1E2, awk also recognizes exponential numeric formats.)
having two columns, A and B.. i need to add another column C in a file and calculate the percentage based on the column A and B. (COLUMN B/ COLUMN A *100) . "|" is delimiter separating the A and B.. need C column with the percentage value. Thanks for your help
100|50 |50% ... (6 Replies)
Hi all, Just want to say thanks for the great forum you have here, the old topics and posts have helped tremendously. So much so that I have managed to figure a lot out just by researching. However, I'm having a small issue that I simply can't find the answer to. (4 Replies)
Hi all
i have a text file with columns delimited with ,
2010-08-18,10,24,.09751,39,7,14872,26732
.
.
.
i would to add a extra column in the end with percentage calculation of columns 5 and 8 ie (39/26732)*100
so the output must look like
... (6 Replies)
Hi
I need a awk script to calculate percentage.
I have to pass the pararmeters in to the awk script and calculate the percentage.
Sum = 50
passed = 43
failed = 7
I need to pass these value in to the awk script and calculate the percentage.
Please advice me. (8 Replies)
how would you calculate percentage by per line? Given a column of 16 lines, grab each line and divide it by the sum of the entire column and multiply by 100?
thanks ... (8 Replies)
Hi, I seem to be getting errors in relation to GCC it seems as I cant upgrade alot of pkgs until I can upgrade or use a later version of GCC.
The error I get is along the lines of ( cc1: error: unrecognized command line option "-Wno-pointer-sign"
*** Error code 1 )
Anyway I was wondering if... (2 Replies)
Discussion started by: Browser
2 Replies
8. Post Here to Contact Site Administrators and Moderators
I have to suggest that we turn HTML back off. The problem is that angle brackets are used in code and this is causing stuff to get dropped from posts.
I know that we can use the constructs that PxT mentions in this thread. But look how hard it is to educate folks about code tags and the search... (4 Replies)
Good day all,
I'm hoping someone can help me understand what the percentage sign is and does in mapping a drive to a server ? I provided the example for you.
(ie \\server1\share%simon)
thanks
simon2000 (2 Replies)