How do I convert a tab-separated values (TSV) file to a comma-separated values (CSV) file in BASH?

后端 未结 4 1277
闹比i
闹比i 2021-02-03 14:07

I have some TSV files that I need to convert to CSV files. Is there any solution in BASH, e.g. using awk, to convert these? I could use sed, like this,

4条回答
  •  情书的邮戳
    2021-02-03 14:22

    Using awk works for me

    converting tsv to csv

    awk 'BEGIN { FS="\t"; OFS="," } {$1=$1; print}' file.tsv > file.csv
    

    or converting csv to tsv

    awk 'BEGIN { FS=","; OFS="\t" } {$1=$1; print}' file.csv > file.tsv
    

提交回复
热议问题