Skip to content

Instantly share code, notes, and snippets.

@ryanaslett
Last active August 29, 2015 14:02
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 ryanaslett/5c693e73f9ecf6977fd6 to your computer and use it in GitHub Desktop.
Save ryanaslett/5c693e73f9ecf6977fd6 to your computer and use it in GitHub Desktop.
Awk funz
# Grabs the third field ($3) in a file, counts how many times that field occurs and outputs it in numeric order.
# This is pretty much the equivalent to a sql statement like the following:
# SELECT COUNT(*) as ROWS, `Third field` FROM `file` GROUP BY `Third field` ORDER BY `ROWS` ASC
awk '{ x[$3]++ } END { for (i in x) print x[i] ":" i }' file |sort -n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment