awk script formatting

Hello,
I have got the following kine in my script
awk '{printf("%s,", $0);next}{printf("%s", $0)}' ORS="," a.txt > b.out

The contents of b looks somewaht like this:
QUEUE(QUEUE1.Q),CURDEPTH(0),QUEUE(QUEUE2.Q),CURDEPTH(0),QUEUE(QUEUE3.Q),CURDEPTH(0)
But my desired output is :
QUEUE(QUEUE1.Q),CURDEPTH(0),
QUEUE(QUEUE2.Q),CURDEPTH(0),
QUEUE(QUEUE3.Q),CURDEPTH(0)
Not good with this awk thing.
Any idea folks.
Thanks in advance.

Can you post your inputfile (a.txt)?

Regards

Looks like this:

QUEUE(QUEUE1.Q)
CURDEPTH(0)
QUEUE(QUEUE2.Q)
CURDEPTH(0)
QUEUE(QUEUE3.Q)
CURDEPTH(0)
...

awk '{ fmt=(!NR%2)?"%s,\n" :"%s,"; printf(fmt, $0) }' t.txt 

Getting a syntax error :frowning:

Try this:

awk 'NR%2{printf("%s,",$0);next}1' a.txt > b.out

Same problem :frowning: ... using a Sun OS 5.8 Solaris box ...

use nawk.

Hello
if input is like
QUEUE(QUEUE1.Q)
CURDEPTH(0)
QUEUE(QUEUE2.Q)
CURDEPTH(0)
QUEUE(QUEUE3.Q)
CURDEPTH(0)

then using command
awk '{ fmt=(!NR%2)?"%s,\n" :"%s,"; printf (fmt, $0) }' file_queue
output display is
QUEUE(QUEUE1.Q),CURDEPTH(0),QUEUE(QUEUE2.Q),CURDEPTH(0),QUEUE(QUEUE3.Q),CURDEPTH(0),

But that king
have a output display like that and
Franklin ---> awk 'NR%2{printf("%s,",$0);next}1' a.txt
then desired come

QUEUE(QUEUE1.Q),CURDEPTH(0)
QUEUE(QUEUE2.Q),CURDEPTH(0)
QUEUE(QUEUE3.Q),CURDEPTH(0)

Yep ... absolutely ...
But I would also like to say one more thing here ...
We have lines like this also in the input file ...
QUEUE(Queue5.Q) CURDEPTH(12)
QUEUE(Queue6.Q) CURDEPTH(11)
I have tried out a few options but the best that I am getting is
QUEUE(Queue1.Q),CURDEPTH(0),QUEUE(Queue2.Q),CURDEPTH(0),QUEUE(Queue3.Q),CURDEPTH(0),QUEUE(Queue5.Q), CURDEPTH(0),QUEUE(Queue6.Q), CURDEPTH(0)
Thanks a lot for ur time :slight_smile:

awk 'NR%2{printf("%s,",$0);next}1' a.txt
tht Franklin have suggested as a solution
tht code will work ...............