Tool to suppress lines where value=0


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Tool to suppress lines where value=0
# 1  
Old 04-09-2012
Tool to suppress lines where value=0

Hello everyone,

Here's the problem, I have a list generated by this command;

Code:
watch -n 5 'iptables -nvL | grep "DROP"'

It generates output that looks like this (severely truncated for clarity)

Code:
Every 5.0s: iptables -nvL | grep "DROP"                                                                                                                
 9573  574K DROP       all  --  *      *       10.1.0.0/16        0.0.0.0/0
    0     0 DROP           all  --  *      *       192.168.0.0/16   0.0.0.0/0

#IP's changed to internal IP's for the example.

There are hundreds of lines in the output, and what I'd like to do is suppress any output where the value in column 1 ("pkts") is zero. Row 2 column 1 of the data shows a value of zero, and these are the lines I'd like to delete. In other words, only see lines where there IS activity. (watch runs every 5 seconds to give something approaching a realtime output)

Much reading in these forums seems to indicate awk is the answer, but if I pipe the results of the above command through awk like this:

| awk '$1 == 0' #remove any rows where the value in column one is zero

there is no output of any kind, which isn't exactly useful Smilie

Could anyone point out what I'm doing wrong please?

Regards & TIA,

putter

Last edited by putter1900; 04-09-2012 at 07:15 AM..
# 2  
Old 04-09-2012
use

Code:
 
awk '$1!=0'
 
or
 
iptables -nvL | awk '$1!=0 && $3~/DROP/'

# 3  
Old 04-09-2012
Quote:
Originally Posted by itkamaraj
use

Code:
 
awk '$1!=0'
 
or
 
iptables -nvL | awk '$1!=0 && $3~/DROP/'

ABSOLUTELY DEAD-ON!! Thanks so much for the clarification

Running either one against a static instance of iptables -nvl works like a charm, like this;

Code:
iptables -nvL | awk '$1!=0 && $3~/DROP/'|sort -rn -k1

For some reason (probably, I suspect, syntax-related in some way) I can't combine that with "watch" to produce the functional equivalent of a "live output"....and that remains an obstacle.

MANY thanks for your help, greatly appreciated!

putter

Last edited by Scrutinizer; 04-09-2012 at 09:03 AM.. Reason: code tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Python: Suppress lines not substituted

Hi all, I started playing around with Python (2.6.6) trying to parse a file. No matter what I tried so far I am not able to print only the lines/group/backreference that have been affected by the substitution. Instead I get also the other lines too File to parse: some more text ... (2 Replies)
Discussion started by: zaxxon
2 Replies

2. Shell Programming and Scripting

How to suppress error in following command?

I have a file containing data in multiple columns. The colums are seperated by pipe (|). I need to extract information as below: myfile_20130929_781;10;100.00 where myfile.txt is the file name. 10 is the number of records in the file starting with 120 and 100.00 is the sum of 26th field of... (16 Replies)
Discussion started by: angshuman
16 Replies

3. Shell Programming and Scripting

Suppress Error Message

How can I suppress a error message being given by awk command in bash shell? (2 Replies)
Discussion started by: Prachi Gupta
2 Replies

4. UNIX for Dummies Questions & Answers

pine email tool suppress prompt to save read messages

Could somebody please advise about how to configure pine/alpine so that on exit it doesn't prompt me to save read messages? Thanks (3 Replies)
Discussion started by: LeoKSimon
3 Replies

5. Shell Programming and Scripting

how to suppress dd output?

I have to stop the output of dd from writing to terminal. Here is the command: sudo dd if=boot1h of="/dev/r$temp1" Here is the output: 2+0 records in 2+0 records out 1024 bytes transferred in 0.000804 secs (1273715 bytes/sec) I have tried >> log.txt but it doesn't work. Is there... (4 Replies)
Discussion started by: msf5042
4 Replies

6. Shell Programming and Scripting

suppress the Connection text

Hi Guys, I am calling a function from my script. The function has to return only one value which is the year. But in the function, i am having connecting statement to the database. The connection information is coming along with the year variable. I want to suppress the connecting... (1 Reply)
Discussion started by: mac4rfree
1 Replies

7. Shell Programming and Scripting

suppress unzip queries

hey i have piece of code working in solaris and same code i want to deploy it in linux but in solaris its not asking for queris but in linux it is !!!! COMMAND ==> unzip $test/alter.war -d $webclientHome/. OUTPUT==> In solaris it proceeds with following traces replace /aa/test.txt?... (4 Replies)
Discussion started by: crackthehit007
4 Replies

8. Shell Programming and Scripting

Suppress awk warnings

Hello everyone, Sorry if this is a bit of an RTM thing, but I can't find any flags for suppressing warnings with awk and Googling (this site too) didn't yield much useful. Does anyone know how to suppress warnings? The warning I'm specifically trying to remove is one warning me that I'm... (1 Reply)
Discussion started by: kdelok
1 Replies

9. Programming

Suppress last N lines printing

Hi, I want to know different ways of suppressing printing of last N lines. Can anyone help? Thanks, Sree (1 Reply)
Discussion started by: chakri400
1 Replies
Login or Register to Ask a Question