Skip to content

Instantly share code, notes, and snippets.

@indraniel
Created October 13, 2015 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indraniel/9413bd93b0db462de914 to your computer and use it in GitHub Desktop.
Save indraniel/9413bd93b0db462de914 to your computer and use it in GitHub Desktop.
transpose a text table
#!/usr/bin/awk -f
# taken from: http://stackoverflow.com/questions/1729824/transpose-a-file-in-bash
{
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"\t"a[i,j];
}
print str
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment