Skip to content

Instantly share code, notes, and snippets.

@breyten
Created April 1, 2013 10:57
Show Gist options
  • Save breyten/5284293 to your computer and use it in GitHub Desktop.
Save breyten/5284293 to your computer and use it in GitHub Desktop.
List a specific field of a tab separated file using AWK
#!/bin/sh
/usr/bin/awk '
BEGIN {
FS="\t";
FIELD_NAME="'$1'";
print FIELD_NAME;
}
NR == 1 {
for(i=0;i<NF;i++){
if ($(i)==FIELD_NAME) {
FIELD_NUM=i;
}
}
}
NR > 1 {
print $(FIELD_NUM)
}' $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment