threshold


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers threshold
# 1  
Old 11-25-2010
threshold

Hi,
I have a table with 14 columns. How can I filter the columns 2-14, so that I get only those rows back in which the data values are >= 6 in 5 or more columns. Smilie

E.g.

A 6 6 3 6 7 8
B 1 2 3 4 5 5
C 2 2 2 6 7 8

Here I should only get back the row A.
I would like to work from the command line.
Many thanks and Happy Thanksgiving.
# 2  
Old 11-25-2010
Code:
#!/bin/sh

echo "A 6 6 3 6 7 8
B 1 2 3 4 5 5
C 2 2 2 6 7 8" |
while read LINE
do
        COUNT=0

        for X in $LINE
        do
                [ -z "${X##[0-9]}" ] && [ "$X" -ge 6 ] && ((COUNT++))
        done

        [ "$COUNT" -ge 5 ] && echo "$LINE"
done

# 3  
Old 11-25-2010
Or with awk:
Code:
awk '{for(i=2;i<=NF;i++) {if($i>=6)c++}} c>=5 {print; c=0}' file

# 4  
Old 11-25-2010
update to save time, when count more than 5, print directly, no need continue count in same line.
Code:
awk '{for(i=2;i<=NF;i++) if($i>=6) {if (++c>=5) {print;c=0;break}}}' file

# 5  
Old 11-26-2010
Thank you! Could you explain me how this command works and what each part of this does. I would like to be able to do it next myself.
Many thanks!
# 6  
Old 11-26-2010
Quote:
Originally Posted by danieladna
Thank you! Could you explain me how this command works and what each part of this does. I would like to be able to do it next myself.
Many thanks!
Code:
awk '{for(i=2;i<=NF;i++) {if($i>=6)c++}} c>=5 {print; c=0}' file


Explanation:
Code:
for(i=2;i<=NF;i++)

Loop through field 2 till the last field.

Code:
{if($i>=6)c++}}

If the value of the field is >= 6 increase counter variable c

Code:
c>=5 {print; c=0}

If c is >= 5 print the line and reset the counter
This User Gave Thanks to Franklin52 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

How the free memory threshold?

If I understand your question correctly, you are asking for an explanation of Solaris memory manager. You'd better ask Oracle that question because you are talking about Solaris kernel internals. The operating system kernel has no reason to kick a process's memory set out of real memory until... (4 Replies)
Discussion started by: hicksd8
4 Replies

2. AIX

Determine threshold for CPU

I'm writing an application that should display whether a system is running “fine” (normal activity) or if it has reached a critical level and thus indicate through a graphical interface using a green-yellow-red color scheme. The server machines in question are running AIX (but it shouldn't differ... (4 Replies)
Discussion started by: ttl_aix
4 Replies

3. UNIX for Advanced & Expert Users

Threshold for open connections

Hey guys, We've been having issues on one of our CentOS 6 servers and one of the java programs that runs on it. As the software hasn't caused issues in the past, I'm wondering if its a problem with the CentOS server. Basically, the software drops it's tcp connection and won't reconnect,... (5 Replies)
Discussion started by: jimbob01
5 Replies

4. UNIX for Dummies Questions & Answers

Threshold for swap memory

hi guys the monitoring team is using a tool for monitoring linux boxes and they set an alarm for swap memory to 10%(critical) I really has no idea when swap memory usage is high.... Can someone recommend me a threshold for this? when is warning or critical and this parameters can affect... (3 Replies)
Discussion started by: karlochacon
3 Replies

5. Shell Programming and Scripting

Diff two files with threshold value

i have two big file which have thousand of line. i have to sort on two key fields then diff the file. if the interger value of one of the column is less then or greater then 1 it should ignore it. for example File1 abc|7000|jhon|2.3 xyz|9000|sam|6.7 pqr|8000|kapi|4.6 File2... (11 Replies)
Discussion started by: Nishi2011
11 Replies

6. Shell Programming and Scripting

get mail when matching with threshold value

HI Guys Below is my file structure and now I want if % is equal and above 95% then I will get the mail with the name of that filesystem and threshold value. Is someone help me ? 55G 33G 22G 61% /mnt/projects/stp2int4_web_runtime 16G 14G 1.7G 90%... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies

7. Solaris

Rootvol above threshold

Hi there, Root filesystem is above threshold, I have search and cleared unwanted files which are filling up space. But the root fs is still above threshold. I don't know about veritas volume management. Can anyone show me how to solve this. Du shows /proc is occupying a lot of space. Most of the... (2 Replies)
Discussion started by: sundar63
2 Replies

8. UNIX for Advanced & Expert Users

Quota threshold

Hi, I am trying to make a script in which the user is notified once the disk space of the environment increases a particular threshold. I have made a script for it but I am facing an error while executing it. Could any one here guide me further?? Script #!/bin/sh warninglimit=350000... (22 Replies)
Discussion started by: Taranjeet Singh
22 Replies

9. Shell Programming and Scripting

apache threshold

Hi folks, how can i check apache threshold values via shell scripting and what factors need to check via shell scripting process or number of users or what. pls do advice me. Thanks, Bash (9 Replies)
Discussion started by: learnbash
9 Replies
Login or Register to Ask a Question