Multiple not statement in AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple not statement in AWK
# 1  
Old 02-01-2011
Multiple not statement in AWK

Hi

I have a logfile that do grow large rapid, so I like to create a new one with needed info.
For some reason the tail -d do not like to redirects its output to a file.
Code:
tail -f  /var/log/daemon.log | grep -vE '(snmpd|ntpd)'

gives me real time log of all lines without "snmpd" and "ntpd"
This is what I what.
Code:
tail -f  /var/log/daemon.log | grep -vE '(snmpd|ntpd)' >newlog

Do not work


Code:
tail -f  /var/log/daemon.log | grep -vE '(snmpd|ntpd)' | tee newlog

Do not work


So I found this working solution:
Code:
tail -f log | awk '{if ($1 == "Rough") print $5 | "tee mySecondFile.txt"}'

I did change some to:
Code:
  tail -f daemon.log | awk '{ if (!($0 ~ /snmpd/) || !($0 ~ /ntpd/)) print | "tee newlog"}'

This gives me the oposit of what I whant. All logs with "snmp" and "ntpd"


So I tried this
Code:
 tail -f daemon.log | awk '{ if (!($0 ~ /snmpd/) || !($0 ~ /ntpd/)) print | "tee newlog"}'

Seems to give me all line and does not remove the lines with "snmpd" and "ntpd"


Any idea of how to get this correct?
# 2  
Old 02-01-2011
Try changing || to &&
# 3  
Old 02-01-2011
Thanks, it works. I did get lost in all and not or statement

But new problem.
If I add 3 or more statement, it gives me error et second &&
Code:
tail -f daemon.log | awk '{ if (!($0 ~ /snmpd/) && !($0 ~ /ntpd/) && !($0 ~ /reject/)) print | "tee newlog"}'
                                                                  ^ syntex error

I have a total of 8 statement I do not like to have in my log.
# 4  
Old 02-01-2011
Strange, what OS are you using?
Also, does this work?
Code:
tail -f daemon.log | awk '!/snmpd|ntpd|reject/{print | "tee newlog"}'

This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 02-01-2011
Wow, works like a dream, and much simpler. Thanks
Running Ubuntu 10.10
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to apply the update statement in multiple servers on multiple dbs at a time .?

Hi , Can any please help the below requirement on all multiple servers and multiple dbs. update configuration set value='yes' ;1) the above statement apply on 31 Databases at a time on different Ip address eg : 10.104.1.12 (unix ip address ) the above ip box contains 4 db's eg : db... (2 Replies)
Discussion started by: venkat918
2 Replies

2. Shell Programming and Scripting

How to Check Multiple conditions in IF statement?

I wish to check two conditions inside the if statement Condition 1: The two file contents should be identical // using cmp command for this. Condition 2: The two filenames should NOT be the same. This is what i did in vain. if ]; then where entry1 and entry2 are ls *.txt | while... (7 Replies)
Discussion started by: mohtashims
7 Replies

3. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

4. Shell Programming and Scripting

Multiple FOR;Singe DO statement

Hi guys, I'm trying to send variable commands from 2 different files but I'm not figuring out how to put 2 "i" variables into the command, can anyone help? This is what is done when I read only 1 file: for i in $(file1.txt);do echo "$i " I'm trying to echo 2 variables, matching the lines... (2 Replies)
Discussion started by: demmel
2 Replies

5. Shell Programming and Scripting

Multiple conditions in a CASE statement

is it possible to use multiple conditions in a CASE statement? And if so, what is the syntax? I'm trying to use one but can't seem to get it right. I want the statement to be CASE $vendor OR $alias condition 1) statements; condition 2) statements; etc. esac but I keep... (25 Replies)
Discussion started by: Straitsfan
25 Replies

6. Shell Programming and Scripting

multiple if statement

#! /bin/csh set umr=UMR foreach i ( `ls`) set file_nm=$i set bh_nm=`echo $file_nm | cut -d"_" -f2` if($bh_nm !=$umr) then { set bh_ext=`echo $file_nm | cut -d"_" -f4` set bh_num_nm="$bh_nm $bh_ext a .txt" mv $file_nm $bh_num_nm } ... (3 Replies)
Discussion started by: jdsignature88
3 Replies

7. UNIX for Dummies Questions & Answers

Initializing multiple variables in one statement

HI, I have 5 variables var1, var2, var3, var4 and var5 I need to initialize all of them to zero. Is there a way to do it in a single line something like this var1=var2=var3=var4=var5=0. I am unable to achieve this. What is going wrong? (2 Replies)
Discussion started by: paku
2 Replies

8. Shell Programming and Scripting

If statement with multiple conditions

I have a script that runs on multiple servers. What I want to do is have the script do the following: if $(hostname) is equal to server or server2 then TO_DIR=go else TO_DIR=stop fi I have tried: if if ] Server is hpux. any ideas? (1 Reply)
Discussion started by: cpolikowsky
1 Replies

9. UNIX for Dummies Questions & Answers

Multiple Condition If statement

Hi, I would like to create an IF statement where if a variable is equal to at least one of 2 (or more) values then the script proceeds. For example: TEST_VAR=2 if ; then echo success! else echo failure fi I understand that the above syntax is wrong but I feel it must be close. Any... (1 Reply)
Discussion started by: msb65
1 Replies

10. UNIX for Dummies Questions & Answers

multiple Logical statement

hi I have following if condition line_by_line="0000000000000tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt" if then echo "Exclusion criteria" else echo "Not exclusion criteria" fi above condition works perfectley but if i add one more logical condition... (3 Replies)
Discussion started by: mahabunta
3 Replies
Login or Register to Ask a Question