Skip to content

Instantly share code, notes, and snippets.

@jvanja
Created January 12, 2016 09:28
Show Gist options
  • Save jvanja/2893df5c38b86f31049c to your computer and use it in GitHub Desktop.
Save jvanja/2893df5c38b86f31049c to your computer and use it in GitHub Desktop.
Useful awk examples
#searches for 'search_term' and prints all columns
awk '/search_term/' file.txt
#searches for 'search_term' and prints columns 1 and 4 separated with tab (the first column is index 1)
awk '/search_term/ {print $1 "\t" $4}' file.txt
#searches for 'search_term' and prints the number of occurances
awk '/search_term/{++cnt} END {print "Count = ", cnt}' file.txt
#print lines having more than 18 characters
awk 'length($0) > 18' file.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment