Compare the text/integer value from the log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare the text/integer value from the log file
# 1  
Old 09-14-2012
MySQL Compare the text/integer value from the log file

i have some log (temp.txt) file like
Code:
temp.txt:
Filesystem size used avail capacity Mounted on
/dev/md/dsk/d30 9.8G 9.7G 14M 100% /opt
/dev/md/dsk/d72 187M 61M 107M 37% /osmf/mgmt
/dev/md/dsk/d71 187M 140M 29M 83% /export/home
/dev/md/dsk/d70 7.9G 4.3G 3.5G 56% /var/crash
/dev/md/dsk/d74 470M 1.0M 422M 1% /osmf/mgmt/esm

i need to validate capacity value(marked as bold) as if greater than 80% and set the flag value as "TRUE".
can any one help me to solve an issue?

Moderator's Comments:
Mod Comment edit by bakunin: Please view this code tag video for how to use code tags when posting code and data.
# 2  
Old 09-14-2012
Try with this..

Code:
awk '{ gsub("%","",$5);if( $5 ~ /[0-9]/ && $5 > 80) {print }}' file

# 3  
Old 09-14-2012
Code:
awk '$5 ~ /^(8[1-9]|9[0-9]|100)%/ {print}' file

# 4  
Old 09-20-2012
Thanks Guys,

i had tried with the below command
Code:
(awk '{ gsub("%","",$5);if( $5 > 80) {print $5 }}' file)

i can get the out put as
Code:
capacity
87
93
83

but i need to validate if ($5 >80) set the flag="TRUE" else flag="FALSE"
so can you please help to solve the problem? Smilie

Last edited by Franklin52; 09-20-2012 at 04:47 AM.. Reason: Please use code tags for data and code samples
# 5  
Old 09-20-2012
Code:
awk 'NR>1{ gsub("%","",$5);if( $5 ~ /[0-9]/ && $5 > 80) {print }}' file

# 6  
Old 09-20-2012
Thanks PAMU

As suggested by you, have used your command and get the out put as

Output:
Code:
-bash-3.2$ awk 'NR>1{ gsub("%","",$5);if( $5 ~ /[0-9]/ && $5 > 80) {print }}' file
/dev/md/dsk/d10 9.8G 8.9G 910M 91 /
/dev/md/dsk/d30 9.8G 9.6G 106M 99 /opt
/dev/md/dsk/d71 187M 140M 29M 83 /export/home

but i want to declare the variable as flag and assign the Boolean value based on result of if condition (if ($5 >80) set the flag="TRUE" else flag="FALSE")

Can you please help here?Smilie

Last edited by Franklin52; 09-20-2012 at 04:48 AM.. Reason: Please use code tags for data and code samples
# 7  
Old 09-20-2012
try this..

Not able to find more efficient way...Smilie

Code:
[[ "$(awk 'NR>1{ gsub("%","",$5);if( $5 ~ /[0-9]/ && $5 > 80){print } }' file)" != "" ]] && STT="True" || STT="False"
echo $STT

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help on awk to compare only integer on particular column

Hi, 0.23 2.94% 0.00 0.00% 17.8G 55.7% 19.6G 40.9% 630 0.00% 0.06 0.77% - - 7524M 22.9% 15.6G 32.6% - - From the above sample output. I need to compare whether the 6th field is more than 10G..if so print the entire line. Here the 6th field is memory TIA (5 Replies)
Discussion started by: Sumanthsv
5 Replies

2. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

3. Shell Programming and Scripting

How to compare floating variables , integer value expected?

I am running some commands and I am trying to get an output into a variable. I am having problem when I try to put that value in while loop, it says integer value expected. What's the best way to accomplish this remaining=$(symclone -sid XXX -f Clone_test query | grep MB | awk '{print... (1 Reply)
Discussion started by: rajsan
1 Replies

4. Shell Programming and Scripting

how to compare string integer with an integer?

hi, how to I do this? i="4.000" if ; then echo "smaller" fi how do I convert the "4.000" to 4? Thanks! (4 Replies)
Discussion started by: h0ujun
4 Replies

5. Shell Programming and Scripting

compare text in log file

Hi all, I am posting the thread similar to previous posts but here my scenario is i need to know what the files size from start date. Here end time file size will be 0. Also need to know how much time does it took to complete in seconds. log file: Name1 START 11:36:45 ... (5 Replies)
Discussion started by: Olivia
5 Replies

6. UNIX for Dummies Questions & Answers

compare decimal and integer values in if in bash shell

i need to do camparisions like the below. For the case when first=10 and second=9.9 the scripts displays process failed. I need to be able to convert the values to integer before doing the comparision. Like 9.9 should be rounded over to 10 before doing comparision. Please advice how can... (3 Replies)
Discussion started by: nehagupta
3 Replies

7. Shell Programming and Scripting

Compare two files based on integer part only

Please see how can I do this: File A (three columns): X1,Y1,1.01 X2,Y2,2.02 X3,Y3,4.03 File B (three columns): X1,Y1,1 X2,Y2,2 X3,Y3,4.0005 Now I have to compare file A and B based on the integer part of column 3. Means first 2 rows should be OK and the third row should not satisfy... (12 Replies)
Discussion started by: yale_work
12 Replies

8. Programming

to compare two integer values stored in char pointers

How can I compare two integer values which is stored in char pointers? suppose I have char *a and char *b having values 10 and 20. how can i find the shorter value? (1 Reply)
Discussion started by: naan
1 Replies

9. Shell Programming and Scripting

how to compare string & integer in unix

Hi All, i am doung sup up of amount column in my file. tot_val=`awk '{a+=$0}END{printf "%.5f\n",a}' amount` then i have a checksum in footer. chk_sum=`tail -1 $FILE_NAME | cut -d~ -f7 | cut -c2-` but the problem is while executing 1st command i am getting : 27720.75000 & while... (3 Replies)
Discussion started by: Amit.Sagpariya
3 Replies

10. Shell Programming and Scripting

Compare integer value with decimal

Hi all, I have a issue... Is it possible to compare integer value with decimal value. If it is not possible,then how can i compare 2 decimal values in born shell.thanks! (3 Replies)
Discussion started by: MARY76
3 Replies
Login or Register to Ask a Question