awk :how to change delimiter without giving all field name

Hi Experts,

i need to change delimiter from tab to ","

sample test file

cat test
A0000368        A29938511       072569352       5        Any 2 for �1.00        BUTCHERS|CAT FOOD|400G  Sep 12 2012 12:00AM     Jan  5 2014 11:59PM     Sep  7 2012 12:00AM     M       2.000   group   5

output

A0000368","A29938511",072569352,"5"," Any 2 for �1.00","BUTCHERS|CAT FOOD|400G","Sep 12 2012 12:00AM","Jan  5 2014 11:59PM","Sep  7 2012 12:00AM","M","2.000","group","5

i have used below codes


awk -F "\t" 'BEGIN {OFS="\",\""} {print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13}' test

now is there anyway without giving all field from $1 to $13 i can achieve same result in awk.

there is way in sed like below

sed 's/    /","/g'

but i dont want to use sed.

Try:

awk '{$1=$1}1' FS='\t' OFS='","' file

By assigning $1 onto itself, one of the fields gets altered and therefore the records gets recalculated and FS gets replaced by the OFS..

--
If you happen to use AIX try:

awk '{$1=x$1}1' FS='\t' OFS='","' file
1 Like

A sed option:-

sed 's/<tab>/","/g'

Robin