Your last edit made the whole thing a bit trickier. The awk instructions needed are going to get a bit furry, so I would advise that you create a awk script file (create a text file with .awk extension e.g. myScript.awk). Copy the following script inside it:
BEGIN { FS="|" }
$3 == "DLT" {
dlt[$1"|"$2]=$3"|"$4"|"$5"|"$6
a[$1"|"$2]++
}
$3 == "STG" {
stg[$1"|"$2]=$3"|"$4"|"$5"|"$6
a[$1"|"$2]++
}
$3 == "MAIN" {
main[$1"|"$2]=$3"|"$4"|"$5"|"$6
a[$1"|"$2]++
}
$3 == "UNLD" {
unld[$1"|"$2]=$3"|"$4"|"$5"|"$6
a[$1"|"$2]++
}
END {
for (key in a) {
if (dlt[key] == "") dlt[key]="|||"
if (stg[key] == "") stg[key]="|||"
if (main[key] == "") main[key]="|||"
if (unld[key] == "") unld[key]="|||"
print key"|"dlt[key]"|"stg[key]"|"main[key]"|"unld[key]
}
}
To use it :
awk -f myScript.awk <input.txt | sort
If you understood the explanation to my initial answer, you should be able to understand this algorithm. This time we make an array for every data type (dlt, stg, main and unld) and store their values at the key corresponding to the first two fields. Array "a" is used to keep track of all possible keys. At the end we go through the keys of array a, and if one of the data arrays is empty at this key, fill it "|||" as you wanted, so that every line ends up with 18 fields.