Reading a list won't make them stick. ShortcutFoo has you type each shortcut, then brings it back just before you'd forget it.
Basics I
5 shortcuts- $1Reference first column
- awk '/pattern/ {action}' fileExecute action for matched pattern 'pattern' on file 'file'
- ;Char to separate two actions
- printPrint current record line
- $0Reference current record line
Variables I
4 shortcuts- $2Reference second column
- FSField separator of input file (default whitespace)
- NFNumber of fields in current record
- NRLine number of the current record
Basics II
7 shortcuts- ^Match beginning of field
- `Match opterator
- !`Do not match operator
- -FCommand line option to specify input field delimiter
- BEGINDenotes block executed once at start
- ENDDenotes block executed once at end
- str1 str2Concat str1 and str2
One-Line Exercises I
7 shortcuts- awk '{print $1}' filePrint first field for each record in file
- awk '/regex/' filePrint only lines that match regex in file
- awk '!/regex/' filePrint only lines that do not match regex in file
- awk '$2 == "foo"' filePrint any line where field 2 is equal to "foo" in file
- awk '$2 != "foo"' filePrint lines where field 2 is NOT equal to "foo" in file
- awk '$1 ` /regex/' filePrint line if field 1 matches regex in file
- awk '$1 !` /regex/' filePrint line if field 1 does NOT match regex in file
Variables II
5 shortcuts- FILENAMEReference current input file
- FNRReference number of the current record relative to current input file
- OFSField separator of the outputted data (default whitespace)
- ORSRecord separator of the outputted data (default newline)
- RSRecord separator of input file (default newline)
Variables III
6 shortcuts- CONVFMTConversion format used when converting numbers (default %.6g)
- SUBSEPSeparates multiple subscripts (default 034)
- OFMTOutput format for numbers (default %.6g)
- ARGCArgument count, assignable
- ARGVArgument array, assignable
- ENVIRONArray of environment variables
Functions I
6 shortcuts- index(s,t)Position in string s where string t occurs, 0 if not found
- length(s)Length of string s (or $0 if no arg)
- randRandom number between 0 and 1
- substr(s,index,len)Return len-char substring of s that begins at index (counted from 1)
- srandSet seed for rand and return previous seed
- int(x)Truncate x to integer value
Functions II
4 shortcuts- split(s,a,fs)Split string s into array a split by fs, returning length of a
- match(s,r)Position in string s where regex r occurs, or 0 if not found
- sub(r,t,s)Substitute t for first occurrence of regex r in string s (or $0 if s not given)
- gsub(r,t,s)Substitute t for all occurrences of regex r in string s
Functions III
4 shortcuts- system(cmd)Execute cmd and return exit status
- tolower(s)String s to lowercase
- toupper(s)String s to uppercase
- getlineSet $0 to next input record from current input file.
One-Line Exercises II
7 shortcuts- awk 'NR!=1{print $1}' filePrint first field for each record in file excluding the first record
- awk 'END{print NR}' fileCount lines in file
- awk '/foo/{n++}; END {print n+0}' filePrint total number of lines that contain foo
- awk '{total=total+NF};END{print total}' filePrint total number of fields in all lines
- awk '/regex/{getline;print}' filePrint line immediately after regex, but not line containing regex in file
- awk 'length > 32' filePrint lines with more than 32 characters in file
- awk 'NR==12' filePrint line number 12 of file