Skip to content

Instantly share code, notes, and snippets.

@austinsonger
Created February 27, 2018 19:52
Show Gist options
  • Save austinsonger/604f9933e3bf0e85b2e348a93f1456fb to your computer and use it in GitHub Desktop.
Save austinsonger/604f9933e3bf0e85b2e348a93f1456fb to your computer and use it in GitHub Desktop.
awk cheatsheet

awk - pattern-directed scanning and processing language

if you're just looking to take columns, take a look at cut

awk normally uses 'space' as a delimiter.

To force the delimiter to a 'tab':

awk -F\t '{ print $0 }' file.txt

print full line with awk

awk -F\t '{ print $0 }' file.txt

taking columns with awk

awk -F\t '{ print $1 }' file.txt awk -F\t '{ print $1"\t"$2 }' file.txt

matching on conditionals

awk -F\t '$1 == 1 { print $0 }' file.txt > matches_one.txt awk -F\t '$1 != 1 { print $0 }' file.txt > does_not_match_one.txt

take all but the first column (sed will eliminate whitespace at beginning)

awk -F\t '{ $1=""; print $0 }' file.txt | sed 's/^\s//'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment