How to print multiple required columns dynamically in a file using the header name?

Hi All,

i am trying to print required multiple columns dynamically from a fie.
But i am able to print only one column at a time.
i am new to shell script, please help me on this issue.

i am using below script

awk -v COLT=$1 '
        NR==1 {
                for (i=1; i<=NF; i++) {
                        if ($i==COLT) {
                                title=i;
                                print $i;
                        }
                }
        }
        NR>1 {
                if (i=title) {
                        print $i;
                }
        }
' file1

while executing i am using file name with column header name in the file. i am getting the required output for one column .
How to add second column details in order to get multiple columns based on header name.

../test2 Avail
Avail
22G
1.9G
1.9G
1.9G
1.9G
780M
379M
379M
0
379M

Desired output:

Used Avail
15G 22G
0 1.9G
0 1.9G
18M 1.9G
0 1.9G
235M 780M
4.0K 379M
40K 379M
4.3G 0
0 379M

Examples:

Cols as listed in file:

awk -v COLT="$*" '
BEGIN {
   c=split(COLT, cols);
   for (i=1; i<=c; i++) print_cols[cols]=cols;
}

{
   line="";
   for (i=1; i<=NF; i++) {
      if (NR==1 && $i in print_cols) out_col=i;
      if (i in out_col) line=line $i FS;
   }
   if (line) print line;
}

' file1

Cols as listed in arguments:

awk -v COLT="$*" '
BEGIN {
   c=split(COLT, cols);
}

NR==1 { for (j=1; j<=c; j++) {for (i=1; i<=NF; i++) if ($i==cols[j]) out_col[cc++]=i }}

{
   line="";
   for (i=0; i<cc; i++) {
      line=line $(out_col) FS;
   }
   if (line) print line;
}

' file1

Keep it simple:

df | awk -vCOLS="3 4" 'BEGIN {NC = split (COLS, C)} {for (i=1; i<=NC; i++) printf "%s\t", $C; print _}'
Used       Available    
5926800    6123416    
 239864    9750808    
2808048    6403748    
7621396    1573996