AWK basics

Printing columns Print all the columns: $ awk ‘{print $0}’ FILE Print the 1 column: $ awk ‘{print $1}’ FILE Print the last column: $ awk ‘{print $NF}’ FILE Print multiple columns: $ awk ‘{print $1 $3}’ FILE Specifying field separator By default, awk uses space and tab as field separator. You can specify how… Continue reading “AWK basics”

awk: print column $# if $#==[value]

If you’re looking for a specific value: awk ‘$2==1 {print $3}’ fileawk ‘$2==1 {print $3}’ file If you’re looking for a string, you have to use quotes otherwise awk will assume it’s a variable name: awk ‘$1 == "findtext" {print $3}’ fileawk ‘$1 == "findtext" {print $3}’ file