AWK doubt

Hello people

I have a doubt about awk... I�m using it to create a condition where I do not want to use the 0 (zero) value of a certain column.

  • This is the original file:

string,number,date
abc,0,20050101
def,1,20060101
ghi,2,20040101
jkl,12,20090101
mno,123,20020101
pqr,1234,20020101
stu,0,20000101

  • This is the awk line that I�m using:

awk -F, 'BEGIN {OSF=","} { if ($2 != 0) print $1, $2, $3}' TEST.csv >> RESULT.csv

However the result is:

date number string
def 1 20060101
ghi 2 20040101
jkl 12 20090101
mno 123 20020101
pqr 1234 20020101

Can anyone tell me why it losts the ",". What am I doing wrong and how can I fix it?

Regards

Rafael Buria

there's a typo
OSF needs to be OFS (Output Field Seperator)
plus u can write print $0 instead
awk -F, 'BEGIN {OFS=","} { if ($2 != 0) print $0}' TEST.csv >> RESULT.csv

Many thanks to you...