awk gsub multiple fields

Hi,

I am trying to execute this line

awk  -F ";"  -v OFS=";" '{gsub(/\./,",",$6); print}' FILE

but for multiple fields $6 $7 $8

Do you have a suggstion?

Tried:

awk  -F ";"  -v OFS="";""  "function GSUB( F ) {gsub(/\./,\",\",$F); print} { GSUB( 6 ); GSUB( 7 ); GSUB( 8 ) } 1" s.final.gb2.csv  >s.final2.csv

But is not working

Thanks

It will work with slight corections:

awk  -F ";"  -v OFS=";"  '
     function GSUB( F ) {gsub(/\./,",",$F)} 
     GSUB( 6 )
     GSUB( 7 )
     GSUB( 8 )
     1
    ' 

If you wanted the OFS to be more than the semicolon, use backslashes for the double quotes.

1 Like

Is there any specific reasons for using " instead of ' ..?

try

awk  -F ";"  -v OFS=";"  'function GSUB(F) {gsub(/\./,",",$F)} {GSUB(6);GSUB(7);GSUB(8)}1' s.final.gb2.csv  >s.final2.csv