James's Ramblings

awk

Created: February 21, 2020

Print the third and fourth column (tab delimited):

awk '{print $3 "\t" $4}' FILE

Print every line containing the word james:

ls -l | awk '/james/ {print $0}'
  • $0 means the entire line.

Print the third and fourth column of every line with with the word vim:

ps -aux | awk '/vim/ {print $3 "\t" $4}'

Count the number of lines containing SOMETHING:

awk '/SOMETHING/{++cnt} END {print "Count = ", cnt}' FILE

Print lines with more than 50 characters:

awk 'length($0) > 50' FILE