Replace field in csv

Hi, I need to replace a field (field 5) in a csv file, based on the content of another field (field 2), something like this:

actual file:

field1, field2, filed3, field4, field5, field6
01,232,abb-pan,679,,pan
02,565,cdf-pan,683,,pan

the result should be:

01,232,abb-pan,679,PASSED,pan

****************

so, if field2 value is 232, then write PASSED in field 5

Im familiar with awk, i tried this:

awk -F, '{
if ($2 == "232") {
pass_ref="PASSED"
**** I'm stuck here, how I replace the field5... in the same file...???***

thanks in advanced....

how about this?

 awk -F, 'BEGIN{OFS=","}{if($2 == 232){$5="PASSED";print}}' 

Thanks for your fast response, but... where I specify the name of the file to be modified...?

I tried:

awk -F, 'BEGIN{OFS=","}{if($2 == 232){$5="PASSED";print}}' alumni*.csv > alumni*.csv

but the files got deleted....

you don't want to redirect to the same file that your reading! as you found out this will truncate the data file. Redirect to a new filename.

ie:

awk -F, 'BEGIN{OFS=","}{if($2 == 232){$5="PASSED";print}}' alumni*.csv > newfile.csv

I can achieve what I need by redirecting to another file, and then renameming those files...

Thanks a lot.... :b: