Transpor usando AWK ou Perl

Oi eu gostaria de usar AWK ou Perl para obter um arquivo de saída no formato abaixo. Meu arquivo de entrada é um arquivo de texto separado por espaço. Isso é semelhante a uma das minhas perguntas anteriores, mas, neste caso, a entrada e a saída não têm formatação. As posições da minha coluna podem mudar, então apreciaria uma técnica que não faz referência ao número da coluna

Arquivo de entrada

id quantity colour shape size colour shape size colour shape size
1 10 blue square 10 red triangle 12 pink circle 20
2 12 yellow pentagon 3 orange rectangle 4 purple oval 6

Saída desejada

id colour shape size
1 blue square 10
1 red triangle 12
1 pink circle 20
2 yellow pentagon 3
2 orange rectangle 4
2 purple oval 6

Eu estou usando este código por Dennis Williamson. O único problema é que a saída que recebo não tem separação de espaço nos campos transpostos. Eu preciso de uma separação de espaço

#!/usr/bin/awk -f
BEGIN {
col_list = "quantity colour shape"
# Use a B ("blank") to add spaces in the output before or
# after a format string (e.g. %6dB), but generally use the numeric argument

# columns to be repeated on multiple lines may appear anywhere in
# the input, but they will be output together at the beginning of the line
repeat_fields["id"]
# since these are individually set we won't use B
repeat_fmt["id"] = "%-1s "
# additional fields to repeat on each line

ncols = split(col_list, cols)

for (i = 1; i <= ncols; i++) {
    col_names[cols[i]]
    forms[cols[i]] = "%-1s"
}
}


# save the positions of the columns using the header line
FNR == 1 {
for (i = 1; i <= NF; i++) {
    if ($i in repeat_fields) {
        repeat[++nrepeats] = i
        repeat_look[i] = i
        rformats[i] = repeat_fmt[$i]
    }
    if ($i in col_names) {
        col_nums[++n] = i
        col_look[i] = i
        formats[i] = forms[$i]
    }
}
# print the header line
for (i = 1; i <= nrepeats; i++) {
    f = rformats[repeat[i]]
    sub("d", "s", f)
    gsub("B", " ", f)
    printf f, $repeat[i]
}
for (i = 1; i <= ncols; i++) {
    f = formats[col_nums[i]]
    sub("d", "s", f)
    gsub("B", " ", f)
    printf f, $col_nums[i]
}
printf "\n"
next
}

{
for (i = 1; i <= NF; i++) {
    if (i in repeat_look) {
        f = rformats[i]
        gsub("B", " ", f)
        repeat_out = repeat_out sprintf(f, $i)

    }
    if (i in col_look) {
        f = formats[i]
        gsub("B", " ", f)
        out = out sprintf(f, $i)
        coln++
    }
    if (coln == ncols) {
        print repeat_out out
        out = ""
        coln = 0
    }
}
repeat_out = ""
}

Saída

id quantitycolourshape
1 10bluesquare
1 redtrianglepink
2 circle12yellow
2 pentagonorangerectangle

Minhas desculpas por não incluir todas as informações sobre o arquivo real anteriormente. Eu fiz isso apenas por simplicidade, mas não capturou todos os meus requisitos.

No meu arquivo atual eu estou olhando para transpor campos n_cell e n_bsc para NODE SITE CHILD

NODE SITE CHILD n_cell n_bsc

Aqui está um link para o arquivo real em que estou trabalhando

questionAnswers(2)

yourAnswerToTheQuestion