Limit output in awk

Hi All,

I want to delimit the output using awk.
For eg::

a,b,c,d,e,f
abc,def,ghi

should change to

a|b|c|d|e|f
abc|def|ghi

Or to put in another way..

OFS will work in the following code if I seperate the values with comma (eg. $1,$2,$3,$4,$5,$6 ). But since the no. of fields are variable, I might have to use some more lengthy steps.
Is there some way to make OFS work if I use following code (or little variation)..

str="a,b,c,d,e,f"
echo "$str" | awk -F"," 'BEGIN{OFS="|"}{print $0}'

Thanks..

awk -F, '{$1=$1}1' OFS="|" file

or:

sed 's/,/|/g' file

or:

tr ',' '|' < file

Thanks Franklin,

Can you please explain the awk one..

thanks..

Sure:

awk -F, '{$1=$1}1' OFS="|" file

Explanation:

Set fieldseparator:

-F,

Rearrange the line with the new fieldseparator:

$1=$1

Print the line, similar to {print $0}:

1

Set new fieldseparator: