Need help on awk to compare only integer on particular column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help on awk to compare only integer on particular column
# 1  
Old 11-02-2017
Need help on awk to compare only integer on particular column

Hi,

Code:
[total]  0.23 2.94%  0.00 0.00% 17.8G 55.7% 19.6G 40.9%   630 0.00%
[system]  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
# 2  
Old 11-02-2017
Any attempts / ideas / thoughts from your side?
# 3  
Old 11-02-2017
@Rudic..I tried teh following..

Code:
awk '$6~/G/{print $6}' | tr -d "G"

Next i thought of using xargs to send the output for comparison..but i didn't get that.
# 4  
Old 11-02-2017
Quote:
Originally Posted by Sumanthsv
@Rudic..I tried teh following..
Code:
awk '$6~/G/{print $6}' | tr -d "G"

Next i thought of using xargs to send the output for comparison..but i didn't get that.
Hello Sumanthsv,

Please always do show us your efforts, as we all are here to learn and help each other.
Could you please try following and let me know if this helps you.
Code:
awk '{$6=$6~/[gG]/?$6:($6~/[mM]/?($6+0)/1024:($6~/[kK]/?($6+0)/(1024*1024):$6))} $6+0>10'  Input_file

Thanks,
R. Singh
# 5  
Old 11-02-2017
Hi @RavinderSingh13.. It's working fine.Thanks a lot
# 6  
Old 11-02-2017
@RavinderSingh13: seeing the long way you go to account for the units and their respective weight factors, I don't understand why you obviously don't count a value with absent units for "bytes" and a weight of 1E-9 (or 2^-30 for binary values)?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need awk or Shell script to compare Column-1 of two different CSV files and print if column-1 matche

Example: I have files in below format file 1: zxc,133,joe@example.com cst,222,xyz@example1.com File 2 Contains: hxd hcd jws zxc cst File 1 has 50000 lines and file 2 has around 30000 lines : Expected Output has to be : hxd hcd jws (5 Replies)
Discussion started by: TestPractice
5 Replies

2. Shell Programming and Scripting

How to compare two column using awk?

Hi team, I have below sample file. It has 4 columns. I want awk script to compare column2 and column4 row by row and print result in new column5 If value matches then result should be MATCHED if not then result should be NOT MATCHED Input file as below UDC_MSISDN,UDC_NPREFIX... (9 Replies)
Discussion started by: shanul karim
9 Replies

3. Shell Programming and Scripting

Compare two files column values using awk

Judi # cat File1 judi /export/home 76 judi /usr 83 judi # judi # cat File2 judi /export/home 79 judi /usr 82 judi # if COLUMN3 of File2 is greater that COLUMN3 of File1, then print File2's lines juid /export/home 79 Code tags please (2 Replies)
Discussion started by: judi
2 Replies

4. Shell Programming and Scripting

How to compare the values of a column in a same file using awk?

Dear Unix experts, I have got a file where I would like to compare the values of second column if first column is same in such a way that the difference between the values is >50. If not, I would like to discard both values. For example, my input file looks like - comp275_c0_seq2 73... (7 Replies)
Discussion started by: utritala
7 Replies

5. Shell Programming and Scripting

Compare the second column of a file with the second column of another in awk

Hi, I know that this topic has been discussed in the past and I've tried to follow all the guidelines. Anyhow, I following describe my problem. I have a file (file1 , no. records = 67) containing pairs of IP addresses as follows (with single space as delimiter between the fields): example... (5 Replies)
Discussion started by: amarn
5 Replies

6. Shell Programming and Scripting

awk compare column n replace with in one file

hi Friends need to compare columns in one file where the data looks like below laptop,IBM phone,samsung car,rental user1,laptop user2,laptop user3,phone want to get output as laptop,IBM phone,samsung car,rental user1,IBM user2,IBM user3,samsung need to seach $2 in array of $1 and... (4 Replies)
Discussion started by: arun1401
4 Replies

7. 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

8. Shell Programming and Scripting

awk compare column with date format

I have this code to compare columns 1 and 10 between file1 and file 2 and give me all records that match column 1 but dont match column 10 However column 10 is date format mm/dd/yy and awk cant read it and compare ...i tried awk < file1 -F~ '{print $10}' and it gave blank screen Is... (1 Reply)
Discussion started by: sigh2010
1 Replies

9. Shell Programming and Scripting

awk column compare

I've been banging my head against the wall to accomplish the following. Given two files: File a.txt 12345 hello 32324 there File b.txt 12345 stuff 45454 howdy 32324 joe If column 1 matches between the two files, then print only the entire line of the 2nd file (b.txt in this... (3 Replies)
Discussion started by: tiggyboo
3 Replies

10. Shell Programming and Scripting

awk compare column between 2 files

Hi, I would like to compare file1 and file2 file1 1 2 3 file2 1 a 2 b 3 c 4 d The result should only print out "d" in file 2. Thanks (3 Replies)
Discussion started by: phamp008
3 Replies
Login or Register to Ask a Question