Multi Record Layout

I have a fixed width source file like this( it has 5 different record types identified by bolded numbers)

N5101ABCD 9820398 2983287
N5102 9s9923 00000000 00
N5103
N5101TTT 9843438 9494994
N5104 sdsd
N5101YYY 7777777 1111111

I need to have like this:
N5101ABCD 9820398 2983287|N5102 9s9923 00000000 00 |N5103||
N5101TTT 9843438 9494994|||N5104 sdsd|
N5101YYY 7777777 1111111||||

Thanks for ur help in advance!

Are there spaces in the columns where there is no value?
But then

First part has space but second is not...

No. of pipes "|" are also not same....

And you have not shared what you have tried...

no... there mite not be spaces...
No of pipes is 4 for all records...since there are 5 record types which belong to a single record...so i havto group all of 'em...
I tried,

<Code> awk 'END{print RS}$0=_[$1]++||NR==1?$0"|":RS$0"|"' ORS= sample.dat</Code>

But it need a unique value for each group...like
01 N5101ABCD 9820398 2983287
01 N5102 9s9923 00000000 00
01 N5103
02 N5101TTT 9843438 9494994
02 N5104 sdsd
03 N5101YYY 7777777 1111111

Moreover, it displays the output like,
01 N5101ABCD 9820398 2983287|01 N5102 9s9923 00000000 00 |01 N5103|
02 N5101TTT 9843438 9494994|02 N5104 sdsd|
03 N5101YYY 7777777 1111111|

I have to get rid of the last pipe(bolded)....before that I have to add a unique value for all groups...and after grouping I havto get rid rid of that unique value also...