When changing the row ( $0 ), awk reconstructs all the columns and places the OFS value between them, which is the default space . You changed the value of $2 , which means that you forced awk revalue $0 .
When you print a line with $0 in the first case, since you did not change any fields, awk did not recount every field and, therefore, the field separator was saved.
To save the field separator, you can specify that with:
BEGIN block:
$ echo "hi,ho" | awk 'BEGIN{FS=OFS=","}/hi/{$2="low";print $0}' hi,low
Using the -v option:
$ echo "hi,ho" | awk -F, -v OFS="," '/hi/{$2="low";print $0}' hi,low
Definition at the end of awk :
$ echo "hi,ho" | awk -F, '/hi/{$2="low";print $0}' OFS="," hi,low
source share