awk (gawk)—pattern scanning and processing language

gawk [ POSIX or Gnu style options ]  –f program–file [ - ] file…

awk scans each input filename for lines that match any of a set of patterns specified in prog. (See Chapter 5, "The gawk Utility: gawk as a Linux Tool." ) In the following example, use awk, nawk, or gawk, depending on your version of awk.

Example A.4.
1    awk '{print $1, $2}' file
2    awk '/John/{print $3, $4}' file
3    awk -F: '{print $3}' /etc/passwd
4    date | awk '{print $6}'

Explanation

  1. Prints the first two fields of file where fields are separated by white space.

  2. Prints fields 3 and 4 if the pattern John is found.

  3. Using a colon as the field separator, prints the third field of the /etc/passwd file.

  4. Sends the output of the ...

Get Linux Shells by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.