Sponsored Content
Top Forums Shell Programming and Scripting Help with awk percentage calculation from a file Post 302988479 by RavinderSingh13 on Tuesday 27th of December 2016 04:59:03 AM
Old 12-27-2016
Hello venkitesh,

Welcome to forums, could you please try following and let me know if this helps.
Code:
awk '{TOT=$2+0;gsub(/[[:digit:]]|\./,X,$2);USED=$3+0;gsub(/[[:digit:]]|\./,X,$3);if(($2 ~ /GB/ || $2 ~ /TB/)&& TOT>=USED){VAL=USED/TOT * 100};if($2 ~ /TB/ && $3 ~ /GB/ && TOT>=USED){VAL=USED/(TOT * 1024) * 100};if(VAL>20){print $1" filesystem has more disk space used than threshold."};VAL=""}'  Input_file

Output will be as follows.
Code:
/test/test1 filesystem has more disk space used than threshold.

So in above code I have put 20 as threshold, you could set it as per your requirement. I hope this helps(It only handles filesystem capacity in either TBs and GBs).
EDIT: Adding a non-one liner form of solution now too.
Code:
awk '{
        TOT=$2+0;
        gsub(/[[:digit:]]|\./,X,$2);
        USED=$3+0;
        gsub(/[[:digit:]]|\./,X,$3);
        if(($2 ~ /GB/ || $2 ~ /TB/) && TOT>=USED){
                                        VAL=USED/TOT * 100
                                  };
        if($2 ~ /TB/ && $3 ~ /GB/ && TOT>=USED){
                                                VAL=USED/(TOT * 1024) * 100
                                               };
        if(VAL>20){
                        print $1" filesystem has more disk space used than threshold."
                  };
        VAL=""
     }
   '   Input_file

Thanks,
R. Singh

Last edited by RavinderSingh13; 12-28-2016 at 02:25 AM..
This User Gave Thanks to RavinderSingh13 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk percentage

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)
Discussion started by: rockiefx
8 Replies

2. Shell Programming and Scripting

Need an AWK script to calculate the percentage

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)
Discussion started by: bobprabhu
8 Replies

3. Shell Programming and Scripting

awk script to count percentage from log file

Hi, I have a log like this : actually i want to get the log like this : where % can get from : 100 * pmTotNoRrcConnectReqSucc / pmTotNoRrcConnectReq Thanks in advance.. :) (8 Replies)
Discussion started by: justbow
8 Replies

4. Shell Programming and Scripting

File Size calculation with AWK

Hello Friends, Im calculating file sizes with below AWK script. I do this before some spesific files are transferred. I run the script it works but after several running it stuck with a limit of 2147483647 (2 Gbytes -1 byte) and cant exceed this. Something is wrong and I can't proceed, would... (1 Reply)
Discussion started by: EAGL€
1 Replies

5. Shell Programming and Scripting

awk/sed percentage calculation

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)
Discussion started by: posner
6 Replies

6. Shell Programming and Scripting

Percentage Calculation in Decimal

Hi, I have two variable and I need to calculate the percentage of them. Example: (b-a)*100/b How can I do it? I need to do it till 2 decimal point. (16 Replies)
Discussion started by: Anupam_Halder
16 Replies

7. Shell Programming and Scripting

Percentage calculation

i am trying to get percentage : but not able to do it: i tried : x=1 y=2 z=`expr $x/$y*100` it is not giving me result can u pls help on this (4 Replies)
Discussion started by: Aditya.Gurgaon
4 Replies

8. Shell Programming and Scripting

find percentage - awk

Please help me with this ... Input file /vol/test1 10G /vol/test2 1G /vol/test3 200G /vol/test4 3G Output File /vol/test1 10G - - 9G - /vol/test2 1024M - - 921M - /vol/test3 200G - - 180G - /vol/test4 3072M - - 2764M - Basically if Column 2 ( which is... (6 Replies)
Discussion started by: greycells
6 Replies

9. Shell Programming and Scripting

Percentage calculation

Hi, I have a text file in below format. I trying to find a solution for finding percentage used for each of the NAMEs. Directory ALLOCATED USED NAME1 93MB 93KB NAME2 25G 62K NAME3 14G 873M NAME4 25G 62K NAME5 20G... (10 Replies)
Discussion started by: ctrld
10 Replies

10. HP-UX

Shell /awk script for Percentage

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)
Discussion started by: kartikirans
6 Replies
EDJE_CC(1)							 The edje compiler							EDJE_CC(1)

NAME
edje_cc - an edje compiler SYNOPSIS
edje_cc [OPTIONS] input_file.edc [output_file.edj] DESCRIPTION
edje_cc is a compiler for edje files EXAMPLES
edje_cc -v file.edc OPTIONS
-id image/directory Add a directory to look in for relative path images -fd font/directory Add a directory to look in for relative path fonts -v Verbose output -no-lossy Do NOT allow images to be lossy -no-comp Do NOT allow images to be stored with lossless compression -no-raw Do NOT allow images to be stored with zero compression (raw) -min-quality VAL Do NOT allow lossy images with quality < VAL (0-100) -max-quality VAL Do NOT allow lossy images with quality > VAL (0-100) -Ddefine_val= to CPP style define to define input macro definitions to the .edc source SEE ALSO
edje_decc(1) edje_recc(1) BUGS
Please reports bugs to the Pkg-E Team <pkg-e-devel@lists.alioth.debian.org> AUTHOR
This man page was written by Ronald Claveau for the Debian GNU/Linux system (but may be used by others). 0.5.0.042 Jan 29, 2007 EDJE_CC(1)
All times are GMT -4. The time now is 10:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy