[awk] Set the output field separator

Created on November 30, 2026

Set OFS to choose the separator that print puts between comma-separated arguments. Suppose users.txt contains these lines.

Alice 30 Tokyo
Bob 28 Osaka

Set OFS to a comma in the BEGIN block, then pass each field separately to print.

awk 'BEGIN{OFS=","}{print $1,$2,$3}' users.txt
Alice,30,Tokyo
Bob,28,Osaka
awk Shell command