Awk with or and not operator


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk with or and not operator
# 1  
Old 06-12-2011
Awk with or and not operator

Code:
awk -F '/' '{ if (($2!="30") print }' f.dat > date_mismatch.dat

The above command is giving the desired results

But I would want use Or in the above but it is returning the complete file
Code:
awk -F '/' '{ if ($2!="30"||$2!="31") print }' f.dat > date_mismatch.dat


Have tried the braces,spacing,quotes but with no use...Any quick help...

I would want this to be in awk

Is there a way of using something like an IN operator

---------- Post updated at 10:25 AM ---------- Previous update was at 10:10 AM ----------

Thanks was able to do using the following

Code:
awk 'BEGIN {OFS=FS="/"; } $2 !~ /30|31|28/' f.dat > date_mismatch.dat


Last edited by pludi; 06-12-2011 at 12:42 PM..
# 2  
Old 06-12-2011
Try
Code:
awk -F '/' '{ if ($2!="30" && $2!="31") print }' f.dat > date_mismatch.dat

or
Code:
awk -F '/' '{ if !($2="30" || $2="31") print }' f.dat > date_mismatch.dat

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using like operator in awk if condition

Hello All, I have developed a script which selects a particular filed from a file ,trims it,searches for a particular pattern and then mail it when found. cat test_file.txt |sed -n '5,$p'|sed -e 's/ //g'|awk -F'|' '{if ($4 !="Alive") print $1,$2,$3,$4}' >> proc_not_alive.txt It is... (4 Replies)
Discussion started by: karthik adiga
4 Replies

2. Shell Programming and Scripting

Plz help me out use OFMT operator in awk programming

Hi While calculating the sum of 6 and 7 fileds it is calculate the wrong value because of floating point like 7898778.10 awk ' BEGIN { FS = OFS = "|" } NR == 1 { next } { UX = $1 OFS $3 OFS $4 OFS $5 p1 +=$6 p2 +=$7 } END { for(i in UX) ... (8 Replies)
Discussion started by: jagu
8 Replies

3. Shell Programming and Scripting

Getting syntax error with awk ternary operator

split($7,a," "); date = a; time = a split(date,d,"/"); month = sprintf("%02d",d); day = sprintf("%02d",d); year = 2000 + d % 100 split(time,t,":"); hour=t; min=t hour >= 12? { hour=hour-12; amPm=" PM" } : amPM=" AM" hour == 0? hour=12 time=sprintf("%02d",hour)":"sprintf("%02d",min)amPm ... (4 Replies)
Discussion started by: Michael Stora
4 Replies

4. Shell Programming and Scripting

awk - output comming strange: for operator ~ and == .

Hi awk experts, I am getting a strange output , may be it is normal but I am unable to comprehend, When Using == operator it is showing correct: # ls -l | awk '{for (i=0;i<=NF;i++) if ( $i =="info" )print $1,$6,$7,$8,$9}' drwx------ Jan 17 10:44 info But When using ~ (equal )... (4 Replies)
Discussion started by: rveri
4 Replies

5. UNIX for Dummies Questions & Answers

awk if statement / equals operator

Hi, I was hoping someone could explain this please :) I'm using bash, scientific linux... and I don't know what else you need to know. With awk '{ if( 0.3 == 0.1*3) print $1}' file.dat nothing will be printed since apparently the two numbers do not equate. (Using 0.3 != 0.1*3 is seen... (4 Replies)
Discussion started by: Golpette
4 Replies

6. Shell Programming and Scripting

awk Help - Comparison Operator problem

Hi, I've tried searching through the forum but I've drawn a blank so i'm going to post here. I'm developing a number of checks on a CSV file, trying to find if any are greater than a max limit. I'm testing it by running it from a command line. The file I'm testing has 8 records. When I... (3 Replies)
Discussion started by: Tmart
3 Replies

7. UNIX for Dummies Questions & Answers

+= operator

im new to bash scripting and im just using online tutorials and trial and error. i wanted to write a script to read numbers from a file and find their sum: #!/bin/bash theSum=0 for line in $(cat numbers.txt) do let "theSum = theSum + $line" echo "$line" done echo "The sum is... (3 Replies)
Discussion started by: astrolux444
3 Replies

8. Shell Programming and Scripting

OR operator syntax question in AWK script

Hi guys, I confused about syntax used in OR script as follow: I have this sample file separated by "|" containing: January|Month No. 1 February|Month No. 2 March|Month No. 3 April|Month No. 4 May|Month No. 5 June|Month No. 6 July|Month No. 7 August|Month No. 8 September|Month No. 9... (11 Replies)
Discussion started by: cgkmal
11 Replies

9. Programming

new operator

Hi, Please clear the 2 questions, 2 Questions, 1) Why the new as a operator? Is there any special reason why it can't be a function like malloc? 2) How are we considering sizeof(),new are as a opearartors? I know + - * / -> , . etc.. are operators, which criteria satisfied by sizeof()... (4 Replies)
Discussion started by: Nagapandi
4 Replies

10. Shell Programming and Scripting

awk returning "[: ==: unary operator expected"

Hi All, I am new to shell scripting and right now I am just limited to using the pre-written scripts. I am in to Infrastructure management where we use different scripts to get the information passed on to the monitoring tools. I am trying to use this script to get the information about the... (2 Replies)
Discussion started by: theamrit
2 Replies
Login or Register to Ask a Question