Define the OFS
, that is, Output Field Separator:
$ echo "qwer,asdf,zxcv" | awk -F',' 'BEGIN{OFS=","}{gsub("a","b",$2); print $0}'
qwer,bsdf,zxcv
Note also that {print $0}
can be skipped and -F
also included in the BEGIN{}
block:
$ echo "qwer,asdf,zxcv" | awk 'BEGIN{FS=OFS=","}{gsub("a","b",$2)} 1'
qwer,bsdf,zxcv
Giving a 1
we give a True condition that is evaluated as {print $0}
as default.