Assuming there are always 2 fields per file and always in the same order, Here's one way to do it with sed:
#!/bin/sh
printf '%s\t%s\n' Colour Hight
sed '
/ *Colour: */ {
s///
h
n
}
/ *Hight: */ {
s///
G
s/\n/\t/g
}
' "$@"
This answer uses the hold space
feature of sed to save the data values from one line to the next.
We use statement grouping with {
and }
. All the commands in the group apply only to the addressed lines, in this case the lines selected by the patterns / *Colour */
and / *Hight */
.
On both the Colour and Hight lines, we first delete the text that was matched (*Colour *
or *Higth *
) with s///
.
On the Colour line, we then hold h
the remaining text in the hold space
, and then skip to the next line of input without printing (n
).
On the Hight line, we get/append G
the contents of the hold space to the pattern space, concatenated with a newline '\n' by sed
. We then subsitute a tab \t
for this newline and sed
prints the output.
This answer should work with all versions of sed
, whether on Linux, FreeBSD, or OS X.