Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple conditions of `and` and `or` in one awk command

Tags:

bash

awk

I am trying to use multiple 'AND' and 'OR' condition in awk but it is not giving me the desired output. Instead it doesn't read the last && conditions that i have given with time '030000'.

awk -F, '{if(substr($2,1,3)=="301" && $15=="996" || $15=="429" && $5>=030000 && $5<=035000) print $2"|"$15"|"$5}' 2017020* | head -10

3014241320|996|235939
3017943809|996|235953
like image 283
user7352907 Avatar asked Mar 10 '23 22:03

user7352907


1 Answers

Looks like you missed parentheses around the OR operation. It should be:

if(substr($2,1,3)=="301" && ($15=="996" || $15=="429") && $5>=030000 && $5<=035000) ...

See boolean algebra.

like image 60
hek2mgl Avatar answered Mar 23 '23 12:03

hek2mgl