If you know you have 4 variables a, x, y, c, and the file is formatted as a tab separated file and you want the exact format as output shown, you can simply use a "Brute Force" method where you check the contents of fields 4 and 6 for the variable name and output the value of field 5 or 7 formatted as shown using printf.
For example, knowing the variable names you can simply output the header row before then processing each records as follows:
awk -F"\t" '
FNR==1 {
print "\t\t\t a x y c"
}
{
printf "%-8s%8s%8s ", $1, $2, $3
if ($4=="a")
printf "%-5s", $5
else if ($6=="a")
printf "%-5s", $7
else
printf "%-5s", " "
if ($4=="x")
printf "%-5s", $5
else if ($6=="x")
printf "%-5s", $7
else
printf "%-5s", " "
if ($4=="y")
printf "%-5s", $5
else if ($6=="y")
printf "%-5s", $7
else
printf "%-5s", " "
if ($4=="c")
printf "%-5s\n", $5
else if ($6=="c")
printf "%-5s\n", $7
else
print ""
}
' tabfile
Example Use/Output
With your input in tabfile you would have:
$ awk -F"\t" '
> FNR==1 {
> print "\t\t\t a x y c"
> }
> {
> printf "%-8s%8s%8s ", $1, $2, $3
>
> if ($4=="a")
> printf "%-5s", $5
> else if ($6=="a")
> printf "%-5s", $7
> else
> printf "%-5s", " "
>
> if ($4=="x")
> printf "%-5s", $5
> else if ($6=="x")
> printf "%-5s", $7
> else
> printf "%-5s", " "
>
> if ($4=="y")
> printf "%-5s", $5
> else if ($6=="y")
> printf "%-5s", $7
> else
> printf "%-5s", " "
>
> if ($4=="c")
> printf "%-5s\n", $5
> else if ($6=="c")
> printf "%-5s\n", $7
> else
> print ""
> }
> ' tabfile
a x y c
13435 830169 830264 95 16
09433 835620 835672 46
30945 838405 838620 21 19
94853 850475 850660 15
04958 865700 865978 98 16
Which provides the desired output. This one-pass approach will also be quite efficient for 450,000 lines of input. Since this is a bit long for a command-line script, you can simply put it in an awk script and call it with the filename. Let me know if you have questions.
As A Script File
Using as a script file, simply put the contents in a file and make it executable, e.g.
#!/usr/bin/awk -f
BEGIN { FS="\t" }
FNR==1 {
print "\t\t\t a x y c"
}
{
printf "%-8s%8s%8s ", $1, $2, $3
if ($4=="a")
printf "%-5s", $5
else if ($6=="a")
printf "%-5s", $7
else
printf "%-5s", " "
if ($4=="x")
printf "%-5s", $5
else if ($6=="x")
printf "%-5s", $7
else
printf "%-5s", " "
if ($4=="y")
printf "%-5s", $5
else if ($6=="y")
printf "%-5s", $7
else
printf "%-5s", " "
if ($4=="c")
printf "%-5s\n", $5
else if ($6=="c")
printf "%-5s\n", $7
else
print ""
}
Saved as awkscript you would chmod +x awkscript and then run:
$ ./awkscript tabfile
a x y c
13435 830169 830264 95 16
09433 835620 835672 46
30945 838405 838620 21 19
94853 850475 850660 15
04958 865700 865978 98 16