Awk AND operator
awk
Solution
Not tested:
awk 'BEGIN {FS=";"} $1 ~ /'$date'/ && $2 == '$area'{......}'
$2 ~ /8/ -> this means if 2nd field contains 8
$2 == 8 -> this means if 2nd field is equal to 8
Problem
A basic question about AND logical operator. I'm trying to extract some fields in my data file niveles.csv based on values of columns 1 and 2. I'd like to write an awk sentence saying "when field1=date and field2=area then print fields 3 to 5". My data file looks like ``` 01-08-12;1;0;0;0 01-08-12;2;1;1;1 01-08-12;3;0;0;1 ................ ``` awk sentence inside a bash script is ``` date=01-08-2012 area=8 awk 'BEGIN {FS=";"} $1 ~ /'$date'/ && $2 ~ /'$area'/ { print $1 " " $2 " " $3 " " $4 " " $5 }' niveles-rams.cs ``` But this just gives fields for the three cases where area number has an 8 inside (8,18 and 28) while I just want only area 8 data ``` 01-08-2012 8 0 0 0 01-08-2012 18 2 2 1 01-08-2012 28 2 1 0 ``` Thanks in advance for your attention, sure it is a simple question for experienced users.