Greping the column with a value greater than 50 with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Greping the column with a value greater than 50 with awk
# 1  
Old 10-07-2011
Greping the column with a value greater than 50 with awk

Hi All,
I am running a command from a remote server using ssh to different servers. I will get a output like below with 4 columns. I want to grab line which is having a coulmn which grate than or equal to 50. How can I do it with Awk or sed ??. I add a space to first row with sed 's/::/:: /g' to make it easier , and tried " awk '{ if ( $2 > 50 || $3 > 50 || $4 > 50 || $5 > 50 ) print $0 }' " this one checking the forum but failed. it is printing whole line. what am i doing wrong, what is the correct syntax.

Code:
server01.domain3.com::0 | 0 | 0 | 0
server02.domain3.com::99 | 0 | 0 | 0
server05.domain3.com::0 | 50 | 50 | 0
server04.domain3.com::1 | 0 | 0 | 0
server03.domain3.com::0 | 0 | 0 | 0
server07.domain3.com::0 | 40 | 0 | 0
server06.domain3.com::0 | 0 | 0 | 0
server08.domain3.com::32 | 0 | 75 | 0
server09.domain3.com::0 | 0 | 0 | 0
server10.domain3.com::0 | 0 | 10| 0
server100.domain3.com::0 | 21 | 0 | 0
server105.domain3.com::0 | 0 | 0 | 50
server101.domain3.com::0 | 0 | 0 | 0
server103.domain3.com::1 | 1 | 1 | 0
server104.domain3.com::50 | 0 | 0 | 101


Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by radoulov; 10-07-2011 at 06:39 AM..
# 2  
Old 10-07-2011
With the default field separator (whitespace) fields 2, 3 and 5 are '|'.

Try
Code:
sed 's/::/|/' | awk -F\| '{ if ( $2 >= 50 || $3 >= 50 || $4 >= 50 || $5 >= 50 ) print $0 }'

(if you need the '::' in the output just pipe it through sed again)

Last edited by CarloM; 10-07-2011 at 06:32 AM..
# 3  
Old 10-07-2011
Quote:
Originally Posted by raghin
I add a space to first row with sed 's/::/:: /g' to make it easier
I cant see the spaces. after the "::" in your input. BTW what makes it easier?

With the given input.. your awk command should work if you place the fields correctly.

Code:
awk -F "[:|]" '{ if ( $3 > 50 || $4 > 50 || $5 > 50 || $6 > 50 ) print $0 }'

# 4  
Old 10-07-2011
You have 2 issues here:
1. Your data is delimited by the "|" character so you need to specify this to awk with the -F argument:
Code:
awk -F "|" '{ if ( $2 > 50 || $3 > 50 || $4 > 50 || $5 > 50 ) print $0 }'

2. You need to separate the first column of figures from the hostname with a pipe before you process the file:
Code:
sed "s/::/::|/g" file | awk -F "|" '{ if ( $2 > 50 || $3 > 50 || $4 > 50 || $5 > 50 ) print $0 }'

This gives you


Code:
server02.domain3.com::|99 | 0 | 0 | 0
server08.domain3.com::|32 | 0 | 75 | 0
server104.domain3.com::|50 | 0 | 0 | 101

# 5  
Old 10-09-2011
No matter more columns you need check

Code:
awk -F"[:|]" '{for (i=3;i<=NF;i++) if ($i>=50){print $0;next}}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Qn on awk greping values

Hello Experts, I was trying to awk out some data out of a text file. Below is a sample file which I have xxx ***Wed Jun 28 18:00:59 CDT 2015 avg-cpu: %user %nice %system %iowait %steal %idle 17.10 0.00 4.56 2.86 0.00 75.48 Device: rrqm/s wrqm/s ... (2 Replies)
Discussion started by: DevAnand
2 Replies

2. Shell Programming and Scripting

awk and greping between lines

i want to grab lines from a file that are between two patterns (including the lines that contain the pattern). here's what im currently doing: data.txt aaa bbb cccc ddd eee ffff ddd code: awk '/bbb/,/fff/ && $0 !~ /ddd/' cdsnmp.sh I want to grab lines between and including bbb... (5 Replies)
Discussion started by: SkySmart
5 Replies

3. UNIX for Beginners Questions & Answers

Compare first column from two csv files with greater than or equal, and less than

I have two csv files of different sizes. The output file needs to have file1 contents on top of file2 contents where file2 col1 is >= to file1 col1, and file2 col1(same value) is < file1 col1 (next value). So basically, some file2 rows will be matched to the same file1 row because it is the closet... (7 Replies)
Discussion started by: aachave1
7 Replies

4. Shell Programming and Scripting

Egrep a number greater than in a column

i'm aware awk can do what i'm trying to do here. but i cant use awk in this scenario given the circumstance of this box. but i need to check if a number is a certain column is over a certain value, say for instance, 20. data: | 12 | 19 | 2000 | 9029333 |... (11 Replies)
Discussion started by: SkySmart
11 Replies

5. Shell Programming and Scripting

awk to substitute third column if first column is greater than interest

A file 2400 2800 PSC000289 3200 3896 PCS000289 3333 3666 PCS000221 222 1000 PCS000222 3299 3600 PSC000289 Question is while if third column is PCS000289 and first column should be greater than 3000, then replace PCS000289 by YES, remaining the others column same. ... (1 Reply)
Discussion started by: cdfd123
1 Replies

6. UNIX for Dummies Questions & Answers

Use sed on column (csv) file if data in colmns is greater > than?

I have a data file that has 14 columns. I cannot use awk or perl but sed is installed on my host. I would like to delete a line if fields 10, 11 or twelve is greater than 999.99. How is this done using sed? :wall: sed '/^*,*,*,*,*,*,*,*,*,*,*,*,*,*,/d' infile 1 2 3 4 ... (2 Replies)
Discussion started by: Chris Eagleson
2 Replies

7. Shell Programming and Scripting

compare files and remove a line from a file if first column is greater than 25

my files are as follows fileA sepearated by tab /t 00 lieferungen 00 attractiop 01 done 02 forness 03 rasp 04 alwaysisng 04 funny 05 done1 fileB funnymou120112 funnymou234470 mou3raspnhdhv rddfgmoudone1438748 so all those record which are greater than 3 and which are not... (4 Replies)
Discussion started by: rajniman
4 Replies

8. Shell Programming and Scripting

search column and delete row if greater than value

Hi, as the title states i need to find a way to search a column for values great than 1000, and if it is, then delete that row. An example 1 7.021 6.967 116.019 4 U 6.980E+07 0.000E+00 e 0 0 0 0 2 8.292 7.908 118.063 3 U 1.440E+07 0.000E+00 e 0 821 814 ... (3 Replies)
Discussion started by: olifu02
3 Replies

9. Shell Programming and Scripting

AWK/SED print if 2nd character in a column is greater than 0

We have an access log where column 8 displays the time in seconds like below: Tj8nQAoNgwsAABov9cIAAAFL - 10.13.131.80 - - (0) - "GET /aaaaa/bbbb/bbbb where column 8 is printed (0). We are trying to find how many entries are there that has column 8 greater than 0. Remember $8 is (0) and not... (5 Replies)
Discussion started by: spacemtn5
5 Replies

10. Shell Programming and Scripting

problem in greping the string from file using awk

I am using awk command for greping an value from the file the file contains .. file ---------------------------- content----------- -------- String main = "81507066666"; ------------------------------ i am greping the above value using awk command NumberToReplace=`cat "file" | grep... (1 Reply)
Discussion started by: vastare
1 Replies
Login or Register to Ask a Question