insert pipes for existing and non-existing records

I have a source file like this,
L4058S462 34329094 F51010141TK1070000483L4058S462 34329094 0232384840 381892 182 5690
L4058S462 34329094 F51020141FIRST CLEARING, LLC A/C 3432-9094
L4058S462 34329094 F51030141JOHAN HOLMQVIST YVSTANGSVAGEN 6
L4058S462 34329094 F51040141VALBO 81892 SWEDEN AIRMAIL 000000000
L4058S462 34329094 F51090141 0000 0
L4058T155 86374984 F51010141TK1070000443L4058T155 86374984 0232384840 4 182 5690
L4058T155 86374984 F51020141FIRST CLEARING, LLC A/C 8637-4984
L4058T155 86374984 F51030141CONFIDENTIAL & CONFIDENTIAL JT TEN
L4058T155 86374984 F510401412801 MARKET STREET SAINT LOUIS MO 63103

Data in Red color is one data set,blue is other data set.
This is a multi-record data, means there are atmost 12 different records for each account(color), which can be identified by Bolded characters.

I need to put pipes in between all existing and non-existing records of particular account, like this,
L4058S462 34329094 F51010141TK1070000483L4058S462 34329094 0232384840 381892 182 5690|L4058S462 34329094 F51020141FIRST CLEARING, LLC A/C 3432-9094|L4058S462 34329094 F51030141JOHAN HOLMQVIST YVSTANGSVAGEN 6|L4058S462 34329094 F51040141VALBO 81892 SWEDEN AIRMAIL 000000000|||||L4058S462 34329094 F51090141 0000 0|||
L4058T155 86374984 F51010141TK1070000443L4058T155 86374984 0232384840 4 182 5690|L4058T155 86374984 F51020141FIRST CLEARING, LLC A/C 8637-4984|L4058T155 86374984 F51030141CONFIDENTIAL & CONFIDENTIAL JT TEN|L4058T155 86374984 F510401412801 MARKET STREET SAINT LOUIS MO 63103||||||||

I need to put pipes for existing and non-existing records as well.

Thanks for the help.

1st field is the keyfld ?

#!/usr/bin/ksh
previd=""
record=""
delimeter="|"
maxrec=12
id=""
restvalues=""

function initrec
{
  i=1
  while ((i<=maxrec))
  do
        rec[$i]=""
        ((i+=1))
  done
}

function printrec
{
  i=1
  record=""
  while ((i<=maxrec))
  do
        record="$record${rec[$i]}$delimeter"
        ((i+=1))
  done
  print "$record"
  initrec
}


function saverec
{
    recnr=${restvalues:12:2}
    rec[$recnr]="$id $restvalues"
}


##MAIN####
initrec

while read id restvalues
do
       [ "$previd" = "" ] && previd="$id"  # 1st line
       [ "$id" != "$previd" ] && printrec && previd="$id" && continue # nextline
       saverec
       previd="$id"
done
# and last ...
printrec
chmod a+rx thisscript
cat somefile |  sort -t " " -k 1,1 | ./thisscript > out.txt