shell - Search for a column by name in awk -
i have file has many columns. let "employee_number" "employee_name" "salary". want display entries in column giving or part of column name. example if input "name" want employee names printed. possible in simple manner using awk? thanks
given script getcol.awk
follows:
begin { colname = argv[1] argv[1] = "" getline (i = 1; <= nf; i++) { if ($i ~ colname) { break; } } if (i > nf) exit } {print $i}
... , input file test.txt
:
apple banana candy deer elephant b c d e b c d e b c d e b c d e b c d e b c d e b c d e
... command:
$ awk -f getcol.awk b <test.txt
... gives following output:
b b b b b b b
note output text not include first line of test file, treated header.
Comments
Post a Comment