AWK - OFS

Hi All,

I have a comma seperated delimited file with 10 columns. I need to convert it into TAB seperated delimited file.

awk -F"," '{print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7"\t"$8"\t"$9"\t"$10}'  a.txt >>  b.txt

how to use OFS to get the same output. I have tried by googling, but it is not working. The reason is, if in future, the column will be added in source file, i have to change my script. Using OFS, i do not need to change it.

This should do the job:

awk -F, '$1=$1' OFS="\t" file

Amit,
If you do not want to use awk, please use below command

cat a.txt | tr "," "\t" > b.txt

Right, but cat is redundant:

tr "," "\t" < a.txt > b.txt

What about sed?

sed 's/,/     /g'

I typed

sed 's/,/TAB/g'

Doesn't work on all systems, maybe you should type:

<Ctrl-V><TAB>