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