Created
January 15, 2015 20:33
-
-
Save christiangenco/ae76179592bcd35f9715 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you, like me, have always known about this `awk` thing | |
# when stealing one liners from Stack Overflow but always put | |
# off actually learning it, here's your 10 second lesson: | |
# Print lines in FILENAME that match pattern (the $0 is a | |
# variable that refers to the entire line, and can be omitted | |
# by default): | |
$ awk '/pattern/{print $0}' FILENAME | |
# ex: find all words that start with a capital A in the dictionary: | |
$ awk '/^A/{print}' /usr/share/dict/words | |
# Awk is also good at splitting lines by whitespace, like this: | |
$ date | |
Thu Jan 15 14:30:36 CST 2015 | |
$ date | awk '{print $1}' | |
Thu | |
$ date | awk '{print $6}' # WHAT YEAR IS IT | |
2015 | |
# Note that if there isn't a pattern, awk matches every line. | |
# Want more? Here's your 20 minute lesson: | |
# https://news.ycombinator.com/item?id=8893302 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment