Skip to content

Instantly share code, notes, and snippets.

@nstjhp
Created March 19, 2014 13:16
Show Gist options
  • Save nstjhp/9641401 to your computer and use it in GitHub Desktop.
Save nstjhp/9641401 to your computer and use it in GitHub Desktop.
Transpose a tab separated file using AKW from a SO answer
#!/usr/bin/awk -f
# http://stackoverflow.com/a/1729980/3275826
# Make sure this directory/file is in your $PATH
# then call as transpose.awk fileName
{
for (i=1; i<=NF; i++) {
a[NR,i] = $i
}
}
NF>p { p = NF }
END {
for(j=1; j<=p; j++) {
str=a[1,j]
for(i=2; i<=NR; i++){
str=str" "a[i,j];
}
print str
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment