Just some crude looking code, for a possible start (without awk)
copy file to file1
// loop thru while data in file
while ($wc -l file1 > 0)
do
// extract data from that first column
matchf = head -1 file1 | cut -f1
// pull out matching lines
grep $matchf < file1 > file3
// now temp file3 has common entries for first unique column value
// put these into your column format
// write these to file4
//
// copy everything but that first column match to file2
grep -v $matchf <file1 >file2
// copy temp file back to working file1
cp file2 file1
done
RudiC's approach in bash using Associative Arrays:-
#!/bin/bash
declare -A LN
declare -A HD
declare -A MX
while read v1 v2 v3
do
LN["$v1"]="$v1"
HD["$v2"]="$v2"
MX["${v1}${v2}"]="$v3"
done < filename
for j in "${LN[@]}"
do
printf "%10s" "$j"
for k in "${HD[@]}"
do
[ -z "${MX[${j}${k}]}" ] && printf "%10s" "null" || printf "%10s" "${MX[${j}${k}]}"
done
printf "\n"
done