Converting Blocks of data to Lines

Converting Blocks of data to Lines

am 01.02.2008 00:51:44 von swimmingly

I have blocks of data delimited by a single numerical value, followed
by pairs of alphanumeric values. I need to convert each block to a
space-separated line (with a comma after the single number, and a dash
inserted in front of each pair in the block).

Before:

1
router1 name1
router2 nameb
router3 name14
router4 namex
225
router1 nameabc
router2 namedef
1999
router1 etcetcetc

Desired output

1, -router1 name1 -router2 nameb -router3 name14 -router4 namex
225, -router1 nameabc -router2 namedef
1999, -router1 etcetcetc

Thanks if you can help ...
--Dan

Re: Converting Blocks of data to Lines

am 01.02.2008 01:03:17 von Janis Papanagnou

swimmingly wrote:
> I have blocks of data delimited by a single numerical value, followed
> by pairs of alphanumeric values. I need to convert each block to a
> space-separated line (with a comma after the single number, and a dash
> inserted in front of each pair in the block).
>
> Before:
>
> 1
> router1 name1
> router2 nameb
> router3 name14
> router4 namex
> 225
> router1 nameabc
> router2 namedef
> 1999
> router1 etcetcetc
>
> Desired output
>
> 1, -router1 name1 -router2 nameb -router3 name14 -router4 namex
> 225, -router1 nameabc -router2 namedef
> 1999, -router1 etcetcetc
>
> Thanks if you can help ...
> --Dan

awk '
NF==1{printf("%s%d, ",d,$1);d=RS}
NF==2{printf("-%s %s ",$1,$2)}
END{print ""}
'

Janis