The awk
is a popular command used to manipulate the text or command output. The print
is a subcommand provided by the awk in order to print data to the standard output. The print subcommand can get different parameters where $2 is one of them. In this tutorial, we examine what awk ‘{ print $2}’ mean.
awk ‘{ print $2; }’
The $
sign is used to express columns for the input text. Columns are generally separated with spaces or tabs. In the following example, we use the following text file which consists of 4 columns.
surname name age location
baydan ismail 38 canakkale
baydan ahmet 9 ankara
baydan ali 9 ankara
baydan elif 12 canakkale
We use the awk ‘{ print $2}’ to print second columns which contain the names.
$ awk '{ print $2 }' names.txt