I have a .CSV file with the below format:column 1,column 2,column 3,column 4,column 5,column 6,column 7,column 8,column 9,column 1012310,42324564756,a simple string with a , comma,string with or, without commas,string 1,USD,12,70%,08/01/2013,23455,12312255564,string, with, multiple, commas,string with or, without commas,string 2,USD,433,70%,07/15/2013,23525,74535243123,string , with commas, and - hypens and: semicolans,string with or, without commas,string 1,CAND,744,70%,05/06/2013,46476,15467534544,lengthy string, with commas, multiple: colans,string with or, without commas,string 2,CAND,388,70%,09/21/2013,5th column of the file has different strings. I need to filter out the file based on the 5th column value. Lets say, I need a new file from the current file which has records only with the value string 1 in its fifth field.For this I tried the below command,awk -F, ' { if toupper($5) == STRING 1) PRINT  }' file1.csv > file2.csvbut it was throwing me an error as following:awk: { if toupper($5) == STRING 1) PRINT }awk: ^ syntax errorawk: { if toupper($5) == STRING 1) PRINT }awk: ^ syntax errorI then used the following which gives me an odd output.awk -F, '$5=string 1 {print}' file1.csv > file2.csvOutput:column 1 column 2 column 3 column 4 string 1 column 6 column 7 column 8 column 9 column 1012310 42324564756 a simple string with a comma string 1 without commas string 1 USD 12 70% 08/01/2013 23455 12312255564 string with string 1 commas string with or without commas string 2 USD 433 70% 07/15/2013 23525 74535243123 string with commas string 1 string with or without commas string 1 CAND 744 70% 05/06/2013 46476 15467534544 lengthy string with commas string 1 string with or without commas string 2 CAND 388 70% 09/21/2013 P.S: I used the toupper command to be on the safe side, as I am not sure if the string will be in lower or higher case. Also, Please advise what is wrong with my code and if the space in the string matters while searching for a pattern using AWK.
Filter a .CSV file based on the 5th column values of a file and print those records into a new file
linux;sed;awk;csv;filter
awk -F ','  'BEGIN {OFS=,} { if (toupper($5) == STRING 1)  print }' file1.csv > file2.csv Output12310,42324564756,a simple string with a , comma,string with or, without commas,string 1,USD,12,70%,08/01/2013,23525,74535243123,string , with commas, and - hypens and: semicolans,string with or, without commas,string 1,CAND,744,70%,05/06/2013,I think This is What you want.