Skip to content

Instantly share code, notes, and snippets.

@jacob-ogre
Last active December 18, 2015 21:09
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 jacob-ogre/5845502 to your computer and use it in GitHub Desktop.
Save jacob-ogre/5845502 to your computer and use it in GitHub Desktop.
bash and awk: functions and aliases for counting columns in tab-, comma-, and space-delimited files. Goes nicely in .bashrc/.bash_profile.
function tab_ncol {
awk 'BEGIN {FS="\t"} ; END{print NF}' $1;
}
alias tncol='tab_ncol'
function comma_ncol {
awk 'BEGIN {FS=","} ; END{print NF}' $1;
}
alias cncol='comma_ncol'
function space_ncol {
awk 'BEGIN {FS=" "} ; END{print NF}' $1;
}
alias sncol='space_ncol'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment