Search for a column by name in awk

Hi,

I have a file that has many columns. Let us say "Employee_number" "Employee_name" "Salary". I want to display all entries in a column by giving all or part of the column name. For example if I input "name" I want all the employee names printed. Is it possible to do this in a simple manner using awk?

$ cat file.txt
Employee_number Employee_name Salary
111 AAAA 1000
222 BBBB 2000
333 CCC 3000

$ awk -f 2.awk -v colname=name file.txt
AAAA
BBBB
CCC

$ cat 2.awk
{
if(NR==1) for(i=1;i<=NF;i++) { if($i~colname) { colnum=i;break} }
else print $colnum
}

Hi Ranjith,
Thanks a lot. It works. In the solaris platform I had to use gawk does not work with awk.

Why is that?