Converting Blocks of data to Lines

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
swimmingly [ Fr, 01 Februar 2008 00:51 ] [ ID #1921484 ]

Re: Converting Blocks of data to Lines

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
Janis Papanagnou [ Fr, 01 Februar 2008 01:03 ] [ ID #1921485 ]
Linux » comp.unix.shell » Converting Blocks of data to Lines

Vorheriges Thema: Script doubt
Nächstes Thema: How to test for a binary file