Get the output of w command in pipe delimited format

Since output of w command have variable number of columns I want to get the output in pipe delimited format. I tried

export OFS="|"; w

but that does not work.

Any ideas?

try

w | awk '{ gsub("[ ]+", "|"); print} '

It gives compilation error

/home/sdesai/rx/src> w | awk '{ gsub("[ ]+", "|"); print}'
awk: syntax error near line 1
awk: illegal statement near line 1

Even this is not sufficient if the field login@ contains "Mon 9am" it will be treated as two separate fields, while we want only one.

I tried it before I posted it no errors.

Assuming you want help:
Please post your current input from w as a sample, and then your expected output.

We also need to know the kind of UNIX because Solaris awk should be nawk instead, for an example of why we need this information.

Sorry, I did not mention UNIX flavor. I am running on SunOS. It works with nawk.

I would say my input would be something like

User     tty           login@  idle   JCPU   PCPU  what
user1    pts/2         7:08am     2      2      2  -ksh
user1    pts/9        Sat 4pm 2days                -ksh
user3    pts/20        7:01am    24                -ksh

I would expect

User|tty|login@|idle|JCPU|PCPU|what
user1|pts/2|7:08am|2|2|2|-ksh
user1|pts/9|Sat4pm|2days|||-ksh
user3|pts/20|7:01am|24|||-ksh