I am very new to awk. I am trying to add a new calculated column. But awk insert the column to the next line rather to the end of the current line. Here is an example of my data:,2013-11-22,12.9,26.0,26.6,,,NWWhat I am trying to do is to add a column at the end containing YES, or NO based on the fifth column (if $5 > 0 YES else NO).Here is my awk command:awk -F, '{    if($5 > 0) print $0, ,YES; else print $0, ,NO}' data.csvThe result is something like this:,2013-11-22,12.9,26.0,26.6,,,NWYESHow can I fix this?
How to print a string at the end of line using awk?
awk
You can assign straight into fields in awk with $N, for N the field number: $9 = YES will add a new field at the end with the value YES:awk -F, -v OFS=, '{ if ($5 > 5) { $9 = YES } else {$9 = NO} };1' dataWhen we assign into $9 we create the ninth field, which is one beyond the end for this data. Putting 1 at the end forces awk's default output to occur, which we'd have suppressed otherwise.For your sample the above gives you:,2013-11-22,12.9,26.0,26.6,,,NW,YESwhich I think is what you wanted.If you want it to be the last field, regardless of how many fields there were to start with, we can use the number of fields NF, making sure we go one beyond it:awk -v OFS=, -F, '{ if ($5 > 5) {$(NF+1)=YES} else {$(NF+1)=NO} };1' data$ accepts any numeric expression, so we can add one to NF to get access to the next available field.