How to convert delimiters with awk

Delimited text often has to move from a tab-separated shell file to a comma-separated import, report, or handoff file. awk can read one simple field separator and print selected fields with a different output separator, which keeps the row shape visible while changing the delimiter.

The -F option sets the input field separator for each record. The OFS variable sets the output field separator used when a print statement separates fields with commas, so print $1, $2, $3 writes the same three fields with the delimiter stored in OFS.

Use this pattern for regular delimited rows where the delimiter does not appear inside a field value. CSV with quoted commas, embedded line breaks, or escaped quotes needs a CSV-aware parser because plain awk splits on the raw separator and can shift columns when quoting rules matter.

Steps to convert delimiters with awk:

  1. Save a small tab-delimited source file.
    staff.tsv
    name	team	region
    Asha	Ops	APAC
    Mika	Data	EMEA
  2. Convert the tab-delimited rows to comma-delimited rows.
    $ awk -F '\t' 'BEGIN { OFS="," } { print $1, $2, $3 }' staff.tsv > staff.csv

    -F '\t' reads tab-separated input, OFS sets the delimiter to write, and print $1, $2, $3 prints the three fields with OFS between them.

  3. Review the converted file.
    $ cat staff.csv
    name,team,region
    Asha,Ops,APAC
    Mika,Data,EMEA
  4. Verify that each converted row still has three fields.
    $ awk -F ',' '{ print NF }' staff.csv
    3
    3
    3

    If any field can contain commas, quotes, or line breaks, stop and use a CSV-aware parser instead of treating comma as a raw split character.