Warm tip: This article is reproduced from stackoverflow.com, please click
awk

How to filter on CSV data using filter on multiple columns

发布于 2020-03-29 21:00:11

I have following data set in csv and would like to filter this on multiple columns using awk (My Version is GNU 3.1.7)

How can i use awk to filter on multiple columns

i used following command but didn't give required result.

awk -F, '{ if ($7="3YM62AE#UUS" && $5="01CS") print $1","$2","$3","$4","$5","$6","$7","$14}' file1.csv > file2.csv

Let me know if i am using correct awk command.

enter image description here

Questioner
Aniruddha Shinde
Viewed
56
RavinderSingh13 2020-01-31 18:38

Could you please try following. Haven't tested it but you need to change from = to ==.

awk '
BEGIN{
  FS=OFS=","
}
{
  if($7=="\"3YM62AE#UUS\"" && $5=="\"01CS\""){
    print $1,$2,$3,$4,$5,$6,$7,$14
  }
}' file1.csv > file2.csv